AttributeUsageAttribute(AttributeTargets) Konstruktor
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Inicializuje novou instanci AttributeUsageAttribute třídy se zadaným seznamem AttributeTargets, AllowMultiple hodnota a Inherited hodnota.
public:
AttributeUsageAttribute(AttributeTargets validOn);
public AttributeUsageAttribute(AttributeTargets validOn);
new AttributeUsageAttribute : AttributeTargets -> AttributeUsageAttribute
Public Sub New (validOn As AttributeTargets)
Parametry
- validOn
- AttributeTargets
Sada hodnot zkombinovaných pomocí bitové operace OR označující, které prvky programu jsou platné.
Příklady
Definice atributu DispId znázorňuje použití bitové operace OR ke kombinování několika AttributeTargets hodnot.
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
Poznámky
Pomocí bitové operace OR můžete zkombinovat několik AttributeTargets hodnot, abyste získali požadovanou kombinaci platných prvků programu.
Výchozí hodnoty vlastností naleznete v části ValidOn, AllowMultiplea Inherited vlastnosti.