BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Attribute System.AttributeUsage(System.AttributeTargets.Class) System.Runtime.InteropServices.ComVisible(true)

Specifies the behavior of a custom attribute when that attribute is defined.

Custom attributes can be applied to various application ("target") elements, such as classes, parameters, and structures (see for the full list). The class contains three properties that govern custom attribute behavior: the kinds of application elements the attribute can be associated with; whether the attribute can or cannot be inherited by derived elements; and whether multiple instances of the attribute can or cannot be allowed on the same target element.

- Constructor
  The set of application elements to which the attribute will be applied. When indicating multiple application elements, is a bitwise OR combination of enumeration values.

  Constructs and initializes a new instance of the class.

  The new instance will be constructed with the specified value of and the properties and set to their default values ( and respectively).

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Boolean

  Gets or sets a value indicating whether more than one instance of a specified attribute is permitted to be applied to any given program element.

  A where indicates more than one instance of the attribute is permitted to be applied; otherwise, . The default is .

  It is expected that compilers will validate this property; this property is not validated during execution.

  The following example demonstrates the use of . If for an attribute is set to , more than one of those attributes can be assigned to any given program element.

  `using System; [AttributeUsageAttribute( AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true )] public class Author : Attribute { public Author(string name) { this.name = name; } public string name; } [Author( "John Doe" )] [Author( "John Q Public" )] class JohnsClass { public static void Main() {} }`

  The following example demonstrates an error that is expected to be caught by compilers: the sample attempts to assign multiple instances of an attribute for which was set to .

  `using System; [AttributeUsageAttribute( AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false )] public class Author : Attribute { public Author(string name) { this.name = name; } public string name; } [Author( "John Doe" )] [Author( "John Q Public" )] class JohnsClass { public static void Main() {} }`

  This should throw an error similar to:

  error CS0579: Duplicate 'Author' attribute

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Boolean

  Gets or sets a value indicating whether the attribute can be inherited by subclasses of the class to which the attribute is applied.

  indicates the attribute is inherited by subclasses; otherwise, . The default is .

  Information on an inherited attribute will be included in the metadata for the class on which it is applied, but will not be included in the metadata for classes that derive from it. A metadata consumer (such as reflection) is required therefore to traverse up the inheritance chain of a class if that consumer is interested in data that is marked inherited, but applied to an ancestor class. There is nothing for the compiler to validate at compile time.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.AttributeTargets

  Gets the set of values sent to the constructor that indicate to which targets the custom attribute can be applied.

  One or more of the values sent to the constructor, combined by a bitwise OR operation.

  This property is read-only.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
0