public enum AttributeTargets
Object
ValueType
Enum
AttributeTargets
mscorlib
BCL
Enumerates the application elements to which it is valid to attach an attribute.
AttributeTargets is used as a parameter for AttributeUsageAttribute to enable an attribute to be associated with one or more kinds of application elements.
The following example demonstrates how AttributeTargets can be used with AttributeUsageAttribute so that a user-defined attribute class, Author, can be applied to structures and classes. The Author attribute is then applied to a class. There is no output.
using System; [AttributeUsageAttribute(AttributeTargets.Class| AttributeTargets.Struct)] public class Author : Attribute { public Author(string Name) { this.name = Name; } string name; } [Author("John Q Public")] class JohnsClass { public static void Main() { } }
FlagsAttribute
System Namespace
AttributeTargets Fields
AttributeTargets.All Field
AttributeTargets.Assembly Field
AttributeTargets.Class Field
AttributeTargets.Constructor Field
AttributeTargets.Delegate Field
AttributeTargets.Enum Field
AttributeTargets.Event Field
AttributeTargets.Field Field
AttributeTargets.GenericParameter Field
AttributeTargets.Interface Field
AttributeTargets.Method Field
AttributeTargets.Module Field
AttributeTargets.Parameter Field
AttributeTargets.Property Field
AttributeTargets.ReturnValue Field
AttributeTargets.Struct Field
AttributeTargets.value__ Field
All = Assembly | 0x2 | Class | Struct | Enum | Constructor | Method | Property | Field | Event | Interface | Parameter | Delegate | ReturnValue | GenericParameter;
Attribute can be applied to any element.
System.AttributeTargets Enum, System Namespace
Assembly = 0x1;
Attribute can be applied to an assembly.
System.AttributeTargets Enum, System Namespace
Class = 0x4;
Attribute can be applied to a class.
System.AttributeTargets Enum, System Namespace
Constructor = 0x20;
Attribute can be applied to a constructor.
System.AttributeTargets Enum, System Namespace
Delegate = 0x1000;
Attribute can be applied to a delegate.
System.AttributeTargets Enum, System Namespace
Enum = 0x10;
Attribute can be applied to an enumeration.
System.AttributeTargets Enum, System Namespace
Event = 0x200;
Attribute can be applied to an event.
System.AttributeTargets Enum, System Namespace
Field = 0x100;
Attribute can be applied to a field.
System.AttributeTargets Enum, System Namespace
GenericParameter = 0x4000;
Attribute can be applied to a generic Parameter.
System.AttributeTargets Enum, System Namespace
Interface = 0x400;
Attribute can be applied to an interface.
System.AttributeTargets Enum, System Namespace
Method = 0x40;
Attribute can be applied to a method.
System.AttributeTargets Enum, System Namespace
Module = 0x2;
Attribute can be applied to a module.
RuntimeInfrastructure
System.AttributeTargets Enum, System Namespace
Parameter = 0x800;
Attribute can be applied to a parameter.
System.AttributeTargets Enum, System Namespace
Property = 0x80;
Attribute can be applied to a property.
System.AttributeTargets Enum, System Namespace
ReturnValue = 0x2000;
Attribute can be applied to a return value.
System.AttributeTargets Enum, System Namespace
Struct = 0x8;
Attribute can be applied to a value type.
System.AttributeTargets Enum, System Namespace
value__;
System.AttributeTargets Enum, System Namespace