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 AttributeUsageAttribute(AttributeTargets validOn
);
// Public Instance Properties
public bool AllowMultiple{set; get; }
public bool Inherited{set; get; }
public AttributeTargets ValidOn{get; }
}
Hierarchy
Object
→
Attribute
→
AttributeUsageAttribute
Valid On
Class
Get C# in a Nutshell, Second Edition 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.