<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://skizzerz.net/DiceRoller/index.php?action=history&amp;feed=atom&amp;title=Dice%2FDiceMacroAttribute</id>
	<title>Dice/DiceMacroAttribute - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://skizzerz.net/DiceRoller/index.php?action=history&amp;feed=atom&amp;title=Dice%2FDiceMacroAttribute"/>
	<link rel="alternate" type="text/html" href="https://skizzerz.net/DiceRoller/index.php?title=Dice/DiceMacroAttribute&amp;action=history"/>
	<updated>2026-05-03T06:54:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://skizzerz.net/DiceRoller/index.php?title=Dice/DiceMacroAttribute&amp;diff=894&amp;oldid=prev</id>
		<title>Skizzerz: Created page with &quot;{{APIdoc|DiceMacroAttribute Class}} An attribute that can be applied to methods which denotes the method is a valid MacroCallback. The {{l|MacroRegistry...&quot;</title>
		<link rel="alternate" type="text/html" href="https://skizzerz.net/DiceRoller/index.php?title=Dice/DiceMacroAttribute&amp;diff=894&amp;oldid=prev"/>
		<updated>2017-08-14T22:00:41Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{APIdoc|DiceMacroAttribute Class}} An attribute that can be applied to methods which denotes the method is a valid &lt;a href=&quot;/DiceRoller/Dice/MacroCallback&quot; title=&quot;Dice/MacroCallback&quot;&gt;MacroCallback&lt;/a&gt;. The {{l|MacroRegistry...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{APIdoc|DiceMacroAttribute Class}}&lt;br /&gt;
An attribute that can be applied to methods which denotes the method is a valid [[Dice/MacroCallback|MacroCallback]]. The {{l|MacroRegistry.RegisterType}} function can be used to register types which contain methods marked with this attribute.&lt;br /&gt;
&lt;br /&gt;
{{ns}}&lt;br /&gt;
&lt;br /&gt;
== Inheritance Hierarchy ==&lt;br /&gt;
System.Object&lt;br /&gt;
: System.Attribute&lt;br /&gt;
:: Dice.DiceMacroAttribute&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]&lt;br /&gt;
public sealed class DiceMacroAttribute : Attribute&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Constructors ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! style=&amp;quot;width: 5em&amp;quot; |&lt;br /&gt;
! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| {{public}} {{method}} || [[/DiceMacroAttribute|DiceMacroAttribute(String)]] || Constructs a new instance of DiceMacroAttribute&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Properties ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! style=&amp;quot;width: 5em&amp;quot; |&lt;br /&gt;
! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| {{public}} {{property}} || [[/Name|Name]] || Gets the name of the macro, which is not necessarily the same as the name of the method the attribute is attached to.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Remarks ==&lt;br /&gt;
This attribute can be applied to a callback to mark it as a macro. In addition to using the attribute, the type containing the decorated methods must be registered via {{l|MacroRegistry.RegisterType}}. This attribute should only ever be applied to public methods whose signature matches {{l|MacroCallback}}.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
The following example demonstrates using DiceMacroAttribute to register two macros, and then registering the type containing those functions.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using Dice;&lt;br /&gt;
&lt;br /&gt;
class Sample&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Roller.DefaultConfig.MacroRegistry.RegisterType(typeof(Sample));&lt;br /&gt;
        var result = Roller.Roll([a]d6 + [b:2]&amp;quot;);&lt;br /&gt;
        Console.WriteLine(result.Value); // retrieves the value of the expression 1d6+2&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    [DiceMacro(&amp;quot;a&amp;quot;)]&lt;br /&gt;
    public static void A(MacroContext context)&lt;br /&gt;
    {&lt;br /&gt;
        context.Value = 1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    [DiceMacro(&amp;quot;b&amp;quot;)]&lt;br /&gt;
    public static void B(MacroContext context)&lt;br /&gt;
    {&lt;br /&gt;
        // context.Arguments[0] is &amp;quot;b&amp;quot; and context.Arguments[1] is &amp;quot;2&amp;quot; in this example&lt;br /&gt;
        context.Value = Convert.ToDecimal(context.Arguments[1]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Skizzerz</name></author>
		
	</entry>
</feed>