AttributeUsageAttribute AttributeUsageAttribute AttributeUsageAttribute AttributeUsageAttribute Class

定义

指定另一个属性类的用法。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)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class AttributeUsageAttribute : Attribute
type AttributeUsageAttribute = class
    inherit Attribute
Public NotInheritable Class AttributeUsageAttribute
Inherits Attribute
继承
AttributeUsageAttributeAttributeUsageAttributeAttributeUsageAttributeAttributeUsageAttribute
属性

注解

在定义您自己的特性类时,可以控制使用通过将放置在其中的方式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.

构造函数

AttributeUsageAttribute(AttributeTargets) AttributeUsageAttribute(AttributeTargets) AttributeUsageAttribute(AttributeTargets) AttributeUsageAttribute(AttributeTargets)

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

属性

AllowMultiple AllowMultiple AllowMultiple AllowMultiple

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

Inherited Inherited Inherited Inherited

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

TypeId TypeId TypeId TypeId

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

(Inherited from Attribute)
ValidOn ValidOn ValidOn ValidOn

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

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

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

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

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

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

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

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

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

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

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(Inherited from Attribute)

适用于

另请参阅