System.Attribute Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Base class for custom attributes.
C# Syntax:
[AttributeUsage(AttributeTargets.All)]
[Serializable]
public abstract class Attribute
Thread Safety
This type is safe for multithreaded operations.
Remarks
The Attribute class contains convenience methods to access and test custom attributes. While any user-defined type can be used as an attribute, it is expected that most attributes will be instances of types derived from Attribute.

All attributes derive directly or indirectly from class Attribute. Attributes can be applied to any target element (see AttributeTargets); multiple instances of an attribute can be applied to the same target element; and attributes can be inherited by an element derived from a target element. Compilers and other development tools use this information to identify which attributes are custom attributes.

Custom attributes can be stored with any element of the metadata. This mechanism can be used to store application-specific information at compile time and access it either at runtime or when another tool reads the metadata.

.NET Framework predefines some attribute types and uses them to control runtime behavior. Some languages predefine attribute types to represent language features not directly represented in the .NET Framework common type system. Users or other tools are welcome to define and use additional attribute types.

For more information about using attributes, see the conceptual topic at MSDN: extendingmetadatausingattributes.

See also:
System Namespace

System.Attribute Member List:

Public Properties
TypeId Read-only

When implemented in a derived class, gets a unique identifier for this Attribute.
Public Methods
Equals Overridden:
Returns a value indicating whether this instance is equal to a specified object.
GetCustomAttribute Overloaded:
GetCustomAttribute(Assembly element, Type attributeType)

Retrieves a custom attribute of a specified type applied to a specified assembly or inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(MemberInfo element, Type attributeType)

Retrieves a custom attribute of a specified type applied to a specified member of a class or inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(Module element, Type attributeType)

Retrieves a custom attribute of a specified type applied to a specified module or inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(ParameterInfo element, Type attributeType)

Retrieves a custom attribute of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(Assembly element, Type attributeType, bool inherit)

Retrieves a custom attribute of a specified type applied to a specified assembly or optionally inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)

Retrieves a custom attribute of a specified type applied to a specified member of a class or optionally inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(Module element, Type attributeType, bool inherit)

Retrieves a custom attribute of a specified type applied to a specified module or optionally inherited from a base class.
GetCustomAttribute Overloaded:
GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)

Retrieves a custom attribute of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Assembly element)

Retrieves an array of the custom attributes of a specified type applied to a specified assembly or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(MemberInfo element)

Retrieves an array of the custom attributes applied to a specified member of a class or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Module element)

Retrieves an array of the custom attributes of a specified type applied to a specified module or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(ParameterInfo element)

Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Assembly element, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified assembly or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Assembly element, Type attributeType)

Retrieves an array of the custom attributes of a specified type applied to a specified assembly or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(MemberInfo element, bool inherit)

Retrieves an array of the custom attributes of a specified member of a class or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(MemberInfo element, Type type)

Retrieves an array of the custom attributes of a specified type applied to a specified member of a class or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Module element, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified module or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Module element, Type attributeType)

Retrieves an array of the custom attributes of a specified type applied to a specified module or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(ParameterInfo element, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(ParameterInfo element, Type attributeType)

Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Assembly element, Type attributeType, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified assembly or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(MemberInfo element, Type type, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified member of a class or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(Module element, Type attributeType, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified module or optionally inherited from a base class.
GetCustomAttributes Overloaded:
GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit)

Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
GetHashCode Overridden:
Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IsDefaultAttribute When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
IsDefined Overloaded:
IsDefined(Assembly element, Type attributeType)

Determines whether any custom attributes of a specified type are applied to a specified assembly.
IsDefined Overloaded:
IsDefined(MemberInfo element, Type attributeType)

Determines whether any custom attributes of a specified type are applied to a specified member of a class or inherited from a base class.
IsDefined Overloaded:
IsDefined(Module element, Type attributeType)

Determines whether any custom attributes of a specified type are applied to a specified module.
IsDefined Overloaded:
IsDefined(ParameterInfo element, Type attributeType)

Determines whether any custom attributes of a specified type are applied to a specified parameter of a member of a class or inherited from a base class.
IsDefined Overloaded:
IsDefined(Assembly element, Type attributeType, bool inherit)

Determines whether any custom attributes of a specified type are applied to a specified assembly.
IsDefined Overloaded:
IsDefined(MemberInfo element, Type attributeType, bool inherit)

Determines whether any custom attributes of a specified type are applied to a specified member of a class or optionally inherited from a base class.
IsDefined Overloaded:
IsDefined(Module element, Type attributeType, bool inherit)

Determines whether any custom attributes of a specified type are applied to a specified module.
IsDefined Overloaded:
IsDefined(ParameterInfo element, Type attributeType, bool inherit)

Determines whether any custom attributes of a specified type are applied to a specified parameter of a member of a class or optionally inherited from a base class.
Match When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the Attribute class.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Attribute Member Details

ctor #1
Summary
Initializes a new instance of the Attribute class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected Attribute();
Remarks
This constructor is only called by classes that derive from Attribute.

Return to top


Property: TypeId (read-only)
Summary
When implemented in a derived class, gets a unique identifier for this Attribute.
C# Syntax:
public virtual object TypeId {get;}
Remarks
As implemented, this identifier is merely the Type of the attribute. However, it is intended that the unique identifier be used to identify two attributes of the same type.

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Returns a value indicating whether this instance is equal to a specified object.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An Object to compare with this instance or null.

Return Value:
true if obj equals the type and value of this instance; otherwise, false.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Attribute();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetCustomAttribute(
   Assembly element,
   Type attributeType
)
Summary
Retrieves a custom attribute of a specified type applied to a specified assembly or inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   Assembly element,
   Type attributeType
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.
Remarks
Use the Attribute.GetCustomAttributes method if you expect more than one value to be returned, or AmbiguousMatchException is thrown.

Return to top


Overloaded Method: GetCustomAttribute(
   MemberInfo element,
   Type attributeType
)
Summary
Retrieves a custom attribute of a specified type applied to a specified member of a class or inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   MemberInfo element,
   Type attributeType
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
AmbiguousMatchException More than one of the requested attributes was found.
Remarks
A match is determined in the same way described in the Return Value section of Type.IsAssignableFrom.

Return to top


Overloaded Method: GetCustomAttribute(
   Module element,
   Type attributeType
)
Summary
Retrieves a custom attribute of a specified type applied to a specified module or inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   Module element,
   Type attributeType
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttribute(
   ParameterInfo element,
   Type attributeType
)
Summary
Retrieves a custom attribute of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   ParameterInfo element,
   Type attributeType
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttribute(
   Assembly element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves a custom attribute of a specified type applied to a specified assembly or optionally inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   Assembly element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttribute(
   MemberInfo element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves a custom attribute of a specified type applied to a specified member of a class or optionally inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   MemberInfo element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

attributeType

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttribute(
   Module element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves a custom attribute of a specified type applied to a specified module or optionally inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   Module element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttribute(
   ParameterInfo element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves a custom attribute of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
C# Syntax:
public static Attribute GetCustomAttribute(
   ParameterInfo element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
null, if no custom attribute of type attributeType is applied to element.

-or-

An Attribute reference to the single custom attribute of type attributeType that is applied to element.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
AmbiguousMatchException More than one of the requested attributes was found.

Return to top


Overloaded Method: GetCustomAttributes(
   Assembly element
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified assembly or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Assembly element
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   MemberInfo element
)
Summary
Retrieves an array of the custom attributes applied to a specified member of a class or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   MemberInfo element
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element is null.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   Module element
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified module or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Module element
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element is null.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   ParameterInfo element
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   ParameterInfo element
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element is null.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   Assembly element,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified assembly or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Assembly element,
   bool inherit
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   Assembly element,
   Type attributeType
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified assembly or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Assembly element,
   Type attributeType
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   MemberInfo element,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified member of a class or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   MemberInfo element,
   bool inherit
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element is null.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   MemberInfo element,
   Type type
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified member of a class or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   MemberInfo element,
   Type type
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

type

The Type object to which the custom attributes are applied.

Return Value:
An Attribute array containing the custom attributes of type type applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or type is null.
ArgumentException type is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   Module element,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified module or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Module element,
   bool inherit
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   Module element,
   Type attributeType
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified module or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Module element,
   Type attributeType
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   ParameterInfo element,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   ParameterInfo element,
   bool inherit
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
An Attribute array containing the custom attributes applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element is null.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   ParameterInfo element,
   Type attributeType
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   ParameterInfo element,
   Type attributeType
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element.

Return to top


Overloaded Method: GetCustomAttributes(
   Assembly element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified assembly or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Assembly element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   MemberInfo element,
   Type type,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified member of a class or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   MemberInfo element,
   Type type,
   bool inherit
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, or property member of a class.

type

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
An Attribute array containing the custom attributes of type type applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or type is null.
ArgumentException type is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   Module element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified module or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   Module element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overloaded Method: GetCustomAttributes(
   ParameterInfo element,
   Type attributeType,
   bool inherit
)
Summary
Retrieves an array of the custom attributes of a specified type applied to a specified parameter of a member of a class or optionally inherited from a base class.
C# Syntax:
public static Attribute[] GetCustomAttributes(
   ParameterInfo element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
An Attribute array containing the custom attributes of type attributeType applied to element.

-or-

An empty array if no such custom attributes exist.

Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
Return value contains the custom attributes for ancestors of element if inherit is true.

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: IsDefaultAttribute()
Summary
When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
C# Syntax:
public virtual bool IsDefaultAttribute();
Return Value:
true if this instance is the default attribute for the class; otherwise, false.
Remarks
The default implementation of this class returns false, and must be implemented in the derived class to be useful to that class.

The implementation of this method in a derived class compares the value of this instance to a standard, default value obtained by some means, then returns a Boolean value that indicates whether the value of this instance is equal to the standard. The standard value is typically coded as a constant in the implementation, or stored programmatically in a field used by the implementation.

Return to top


Overloaded Method: IsDefined(
   Assembly element,
   Type attributeType
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified assembly.
C# Syntax:
public static bool IsDefined(
   Assembly element,
   Type attributeType
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
The ancestors of element are not searched for custom attributes.

Return to top


Overloaded Method: IsDefined(
   MemberInfo element,
   Type attributeType
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified member of a class or inherited from a base class.
C# Syntax:
public static bool IsDefined(
   MemberInfo element,
   Type attributeType
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, type, or property member of a class.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
The ancestors of element are searched for custom attributes if element is a method or a type.

Return to top


Overloaded Method: IsDefined(
   Module element,
   Type attributeType
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified module.
C# Syntax:
public static bool IsDefined(
   Module element,
   Type attributeType
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
The ancestors of element are not searched for custom attributes.

Return to top


Overloaded Method: IsDefined(
   ParameterInfo element,
   Type attributeType
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified parameter of a member of a class or inherited from a base class.
C# Syntax:
public static bool IsDefined(
   ParameterInfo element,
   Type attributeType
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
The ancestors of element are searched for custom attributes.

Return to top


Overloaded Method: IsDefined(
   Assembly element,
   Type attributeType,
   bool inherit
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified assembly.
C# Syntax:
public static bool IsDefined(
   Assembly element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Assembly that describes a reusable, versionable, collection of modules.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
This method ignores the value of parameter inherit. The ancestors of element are not searched for custom attributes.

Return to top


Overloaded Method: IsDefined(
   MemberInfo element,
   Type attributeType,
   bool inherit
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified member of a class or optionally inherited from a base class.
C# Syntax:
public static bool IsDefined(
   MemberInfo element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class MemberInfo that describes a constructor, event, field, method, type, or property member of a class.

attributeType

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
NotSupportedException element is not a constructor, method, property, event, type, or field.
Remarks
The ancestors of element are searched for custom attributes if inherit is true and element is a method or a type.inherit is ignored if element is a constructor, field, property, or event.

Return to top


Overloaded Method: IsDefined(
   Module element,
   Type attributeType,
   bool inherit
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified module.
C# Syntax:
public static bool IsDefined(
   Module element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class Module that describes a portable executable file.

attributeType

The Type object to which the custom attributes are applied.

inherit

This parameter is ignored, and does not affect the operation of this method.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
Remarks
This method ignores the value of parameter inherit. The ancestors of element are not searched for custom attributes.

Return to top


Overloaded Method: IsDefined(
   ParameterInfo element,
   Type attributeType,
   bool inherit
)
Summary
Determines whether any custom attributes of a specified type are applied to a specified parameter of a member of a class or optionally inherited from a base class.
C# Syntax:
public static bool IsDefined(
   ParameterInfo element,
   Type attributeType,
   bool inherit
);
Parameters:

element

An object derived from class ParameterInfo that describes a parameter of a member of a class.

attributeType

The Type object to which the custom attributes are applied.

inherit

If true, specifies to also search the ancestors of element for custom attributes.

Return Value:
true if a custom attribute of type attributeType is applied to element; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException element or attributeType is null.
ArgumentException attributeType is not derived from Attribute.
ExecutionEngineException element is not a method, constructor, or type.
Remarks
The ancestors of element are searched for custom attributes if inherit is true and element is a method.inherit is ignored if element is a constructor or a type.

Return to top


Method: Match(
   object obj
)
Summary
When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
C# Syntax:
public virtual bool Match(
   object obj
);
Parameters:

obj

An Object to compare with this instance of Attribute.

Return Value:
true if this instance equals obj; otherwise, false.
Remarks
This method determines if one Attribute equals another. Its default implementation is the same as Attribute.Equals, which performs a value and reference comparison. Override this method to implement support for attribute values, such as flags or bitfields, that consist of components that are meaningful in themselves. For example, consider an attribute whose value is a binary field divided into a bitfield of flags. Two instances of this attribute have one flag in set in common while all the other flags differ. The Equal method cannot determine that the two instances have the same flag set, but the Match method can.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.