< Day Day Up > |
TechniqueYou should specify the AllowMultiple property of the AttributeUsage attribute, as shown in Listing 25.9. Listing 25.9 Add a Title Here[AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class MyMultipleAttribute : Attribute { // etc. With the definition of MyMultipleAttribute in Listing 25.9, and with the additional assumption that MyMultipleAttribute has a constructor that takes a string, you can use MyMultipleAttribute as shown in Listing 25.10. Listing 25.10 Using an Attribute More Than Once on the Same Target[MyMultipleAttribute("This is some text")] [MyMultipleAttribute("Hey, this is some more text!")] public override void SomeMethod() { // etc. If we had not specified AllowMultiple=true in Listing 25.9, then Listing 25.10 would have resulted in a compilation error, because the default behavior is that a given attribute cannot be applied more than once to the same target. |
< Day Day Up > |