AttributeUsageAttribute 类


指定另一个属性类的用法。Specifies the usage of another attribute class. 此类不能被继承。This class cannot be inherited.

public ref class AttributeUsageAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, Inherited=true)]
public sealed class AttributeUsageAttribute : Attribute
type AttributeUsageAttribute = class
    inherit Attribute
Public NotInheritable Class AttributeUsageAttribute
Inherits Attribute


定义自己的属性类时, 可以通过AttributeUsageAttribute在属性类上放置来控制使用它的方式。When you are defining your own attribute class, you can control the manner in which it is used by placing an AttributeUsageAttribute on your attribute class. 指示的特性类必须直接或Attribute间接从派生。The indicated attribute class must derive from Attribute, either directly or indirectly.

特性类具有位置和命名参数。Attribute classes have positional and named parameters. 特性类的每个公共构造函数定义该类的有效位置参数序列。Each public constructor for an attribute class defines a valid sequence of positional parameters for that class. 命名参数由特性类的非静态、公共和读/写字段或属性定义。Named parameters are defined by the non-static, public, and read-write fields or properties of the attribute class.

的三个属性AttributeUsageAttribute是通过定义以下参数设置的:The three properties of AttributeUsageAttribute are set by defining the following parameters:

此位置参数指定指示的属性可放置到的程序元素。This positional parameter specifies the program elements that the indicated attribute can be placed on. AttributeTargets枚举中列出了可以放置属性的所有可能元素的集合。The set of all possible elements that you can place an attribute on is listed in the AttributeTargets enumeration. 可以使用按位AttributeTargets "或" 运算组合几个值, 以获取所需的有效程序元素组合。You can combine several AttributeTargets values using a bitwise OR operation to get the desired combination of valid program elements.

此命名参数指定是否可为给定的程序元素多次指定指定的属性。This named parameter specifies whether the indicated attribute can be specified more than once for a given program element.

此命名参数指定所指示的属性是否可由派生类和重写成员继承。This named parameter specifies whether the indicated attribute can be inherited by derived classes and overriding members.

有关使用特性的详细信息, 请Attribute参阅和特性For more information about using attributes, see Attribute and Attributes.



用指定的 AttributeUsageAttributeAttributeTargets 值和 AllowMultiple 值列表初始化 Inherited 类的新实例。Initializes a new instance of the AttributeUsageAttribute class with the specified list of AttributeTargets, the AllowMultiple value, and the Inherited value.



获取或设置一个布尔值,该值指示能否为一个程序元素指定多个指示属性实例。Gets or sets a Boolean value indicating whether more than one instance of the indicated attribute can be specified for a single program element.


获取或设置 Boolean 值,该值确定指示的属性是否由派生类和重写成员继承。Gets or sets a Boolean value that determines whether the indicated attribute is inherited by derived classes and overriding members.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

获取一组值,这组值标识指示的属性可应用到的程序元素。Gets a set of values identifying which program elements that the indicated attribute can be applied to.



返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)