O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

AttributeUsageAttribute

Synopsis

This attribute is used when developing a custom attribute class. It allows you to specify how your custom attribute must be used. The ValidOn property uses a bitwise combination of values from AttributeTargets to specify the code elements that can use your custom attribute. It’s read-only and must be initialized using the constructor, as in [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)].

The AllowMultiple property specifies whether the attribute can be used more than once for the same element. The Inherited attribute specifies whether your custom attribute will be applied to derived classes and overridden members. These are indicated using the usual named parameter syntax supported by attributes, as in [AttributeUsage(Inherited = true, AllowMultiple = true)]

public sealed class AttributeUsageAttribute : Attribute {
// Public Constructors
   public method AttributeUsageAttribute(
        AttributeTargets validOn);  
// Public Instance Properties
   public field bool AllowMultiple{set; get; } 
   public field bool Inherited{set; get; } 
   public field AttributeTargets ValidOn{get; } 
}

Hierarchy

ObjectAttributeAttributeUsageAttribute

Valid On

Class

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required