AttributeTargets Enumeration
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: SystemAssembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ <FlagsAttribute> _ Public Enumeration AttributeTargets 'Usage Dim instance As AttributeTargets
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute FlagsAttribute() */ public enum AttributeTargets
SerializableAttribute ComVisibleAttribute(true) FlagsAttribute public enum AttributeTargets
| Member name | Description | |||
|---|---|---|---|---|
![]() | All | Attribute can be applied to any application element. | ||
![]() | Assembly | Attribute can be applied to an assembly. | ||
![]() | Class | Attribute can be applied to a class. | ||
![]() | Constructor | Attribute can be applied to a constructor. | ||
![]() | Delegate | Attribute can be applied to a delegate. | ||
![]() | Enum | Attribute can be applied to an enumeration. | ||
![]() | Event | Attribute can be applied to an event. | ||
![]() | Field | Attribute can be applied to a field. | ||
![]() | GenericParameter | Attribute can be applied to a generic parameter. | ||
![]() | Interface | Attribute can be applied to an interface. | ||
![]() | Method | Attribute can be applied to a method. | ||
![]() | Module | Attribute can be applied to a module.
| ||
![]() | Parameter | Attribute can be applied to a parameter. | ||
![]() | Property | Attribute can be applied to a property. | ||
![]() | ReturnValue | Attribute can be applied to a return value. | ||
![]() | Struct | Attribute can be applied to a structure; that is, a value type. |
AttributeTargets is used as a parameter of AttributeUsageAttribute to specify the kind of element on which it is valid to apply an attribute.
AttributeTargets enumeration values can be combined with a bitwise OR operation to get the preferred combination.
The following code sample illustrates the application of the AttributeTargets enumeration:
Imports System Module DemoModule ' This attribute is only valid on a class. <AttributeUsage(AttributeTargets.Class)> _ Public Class ClassTargetAttribute Inherits Attribute End Class ' This attribute is only valid on a method. <AttributeUsage(AttributeTargets.Method)> _ Public Class MethodTargetAttribute Inherits Attribute End Class ' This attribute is only valid on a constructor. <AttributeUsage(AttributeTargets.Constructor)> _ Public Class ConstructorTargetAttribute Inherits Attribute End Class ' This attribute is only valid on a field. <AttributeUsage(AttributeTargets.Field)> _ Public Class FieldTargetAttribute Inherits Attribute End Class ' This attribute is valid on a class or a method. <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Method)> _ Public Class ClassMethodTargetAttribute Inherits Attribute End Class ' This attribute is valid on any target. <AttributeUsage(AttributeTargets.All)> _ Public Class AllTargetsAttribute Inherits Attribute End Class <ClassTarget, _ ClassMethodTarget, _ AllTargets> _ Public Class TestClassAttribute <ConstructorTarget, _ AllTargets> _ Public Sub New End Sub <MethodTarget, _ ClassMethodTarget, _ AllTargets> _ Public Sub Method1() End Sub <FieldTarget, _ AllTargets> _ Public myInt as Integer End Class Sub Main() End Sub End Module
package AttTargsJSL;
import System.*;
// This attribute is only valid on a class.
/** @attribute AttributeUsage(AttributeTargets.Class)
*/
public class ClassTargetAttribute extends Attribute
{
} //ClassTargetAttribute
// This attribute is only valid on a method.
/** @attribute AttributeUsage(AttributeTargets.Method)
*/
public class MethodTargetAttribute extends Attribute
{
} //MethodTargetAttribute
// This attribute is only valid on a constructor.
/** @attribute AttributeUsage(AttributeTargets.Constructor)
*/
public class ConstructorTargetAttribute extends Attribute
{
} //ConstructorTargetAttribute
// This attribute is only valid on a field.
/** @attribute AttributeUsage(AttributeTargets.Field)
*/
public class FieldTargetAttribute extends Attribute
{
} //FieldTargetAttribute
// This attribute is valid on a class or a method.
/** @attribute AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)
*/
public class ClassMethodTargetAttribute extends Attribute
{
} //ClassMethodTargetAttribute
// This attribute is valid on any target.
/** @attribute AttributeUsage(AttributeTargets.All)
*/
public class AllTargetsAttribute extends Attribute
{
} //AllTargetsAttribute
/** @attribute ClassTarget()
*/
/** @attribute ClassMethodTarget()
*/
/** @attribute AllTargets()
*/
public class TestClassAttribute
{
/** @attribute.ConstructorTarget ConstructorTarget()
*/
/** @attribute AllTargets()
*/
TestClassAttribute()
{
} //TestClassAttribute
/** @attribute MethodTarget()
*/
/** @attribute ClassMethodTarget()
*/
/** @attribute AllTargets()
*/
public void Method1()
{
} //Method1
/** @attribute FieldTarget()
*/
/** @attribute AllTargets()
*/
public int myInt;
public static void main(String[] args)
{
} //main
} //TestClassAttribute
import System; package AttTargsJS { // This attribute is only valid on a class. AttributeUsage(AttributeTargets.Class) public class ClassTargetAttribute extends Attribute { } // This attribute is only valid on a method. AttributeUsage(AttributeTargets.Method) public class MethodTargetAttribute extends Attribute { } // This attribute is only valid on a constructor. AttributeUsage(AttributeTargets.Constructor) public class ConstructorTargetAttribute extends Attribute { } // This attribute is only valid on a field. AttributeUsage(AttributeTargets.Field) public class FieldTargetAttribute extends Attribute { } // This attribute is valid on a class or a method. AttributeUsage(AttributeTargets.Class|AttributeTargets.Method) public class ClassMethodTargetAttribute extends Attribute { } // This attribute is valid on any target. AttributeUsage(AttributeTargets.All) public class AllTargetsAttribute extends Attribute { } ClassTargetAttribute ClassMethodTargetAttribute AllTargetsAttribute public class TestClassAttribute { ConstructorTargetAttribute AllTargetsAttribute function TestClassAttribute() { } MethodTargetAttribute ClassMethodTargetAttribute AllTargetsAttribute public function Method1() { } FieldTargetAttribute AllTargetsAttribute public var myInt : int; static function Main(args : String[]) { } } }
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
