AttributeUsageAttribute(AttributeTargets) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用指定的列表AttributeUsageAttribute、AttributeTargets值和AllowMultiple值初始化类的新实例Inherited。
public:
AttributeUsageAttribute(AttributeTargets validOn);
public AttributeUsageAttribute(AttributeTargets validOn);
new AttributeUsageAttribute : AttributeTargets -> AttributeUsageAttribute
Public Sub New (validOn As AttributeTargets)
参数
- validOn
- AttributeTargets
使用按位 OR 操作组合的值集,以指示哪些程序元素有效。
示例
DispId 属性的定义说明了如何使用按位 OR 操作合并多个 AttributeTargets 值。
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field |
AttributeTargets.Property)]
public class DispIdAttribute: System.Attribute
{
public DispIdAttribute(int value) {
// . . .
}
public int Value {
get {
// . . .
return 0;
}
}
}
}
namespace System.Runtime.InteropServices
open System
[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Field ||| AttributeTargets.Property)>]
type DispIdAttribute(value: int) =
inherit Attribute()
// . . .
member _.Value with get() =
// . . .
0
Namespace System.Runtime.InteropServices
<AttributeUsage(AttributeTargets.Method _
Or AttributeTargets.Field _
Or AttributeTargets.Property)> _
Public Class DispIdAttribute
Inherits System.Attribute
Public Sub New(value As Integer)
' . . .
End Sub
Public ReadOnly Property Value() As Integer
Get
' . . .
Return 0
End Get
End Property
End Class
End Namespace
注解
可以使用按位 OR 操作组合多个 AttributeTargets 值来获取有效程序元素的所需组合。
有关默认属性值,请参阅属性ValidOnAllowMultiple和Inherited属性。