To create a float-based attribute in C#, you can declare it as follows:
main.cs307 chars16 linesThis attribute takes a float value in the constructor, which serves as the base value. It also has a method called GetValue which accepts a modifier parameter that is used to output the final value.
To use this attribute, simply apply it to a property:
main.cs85 chars6 lines
In this example, the MyProperty property has been decorated with the MyFloat attribute, and has a base value of 10.0f. To retrieve the final value, you would call GetValue on an instance of the attribute, passing in the modifier value:
main.cs235 chars4 lines
In this example, finalValue is calculated by calling GetValue on the MyFloat attribute that is applied to the MyProperty property. The 2.0f value serves as the modifier.
gistlibby LogSnag