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

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.