Mono Class Library: System Namespace

System.AttributeTargets Enumeration

Enumerates the application elements to which it is valid to attach an attribute. [Edit]
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum AttributeTargets

Remarks

AttributeTargets is used as a parameter for AttributeUsageAttribute to enable an attribute to be associated with one or more kinds of application elements. [Edit]

Members

Member NameDescription
All Attribute can be applied to any element. [Edit]
Assembly Attribute can be applied to an assembly. [Edit]
Class Attribute can be applied to a class. [Edit]
Constructor Attribute can be applied to a constructor. [Edit]
Delegate Attribute can be applied to a delegate. [Edit]
Enum Attribute can be applied to an enumeration. [Edit]
Event Attribute can be applied to an event. [Edit]
Field Attribute can be applied to a field. [Edit]
GenericParameterAttribute can be applied to a generic Parameter. [Edit]
Interface Attribute can be applied to an interface. [Edit]
Method Attribute can be applied to a method. [Edit]
Module Attribute can be applied to a module. [Edit]
Parameter Attribute can be applied to a parameter. [Edit]
Property Attribute can be applied to a property. [Edit]
ReturnValueAttribute can be applied to a return value. [Edit]
Struct Attribute can be applied to a value type. [Edit]

Example

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.

C# Example
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() {
   }
}

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0