AttributeUsageAttribute(AttributeTargets) Construtor
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da AttributeUsageAttribute classe com a lista especificada de AttributeTargets, o AllowMultiple valor e o Inherited valor.
public:
AttributeUsageAttribute(AttributeTargets validOn);
public AttributeUsageAttribute(AttributeTargets validOn);
new AttributeUsageAttribute : AttributeTargets -> AttributeUsageAttribute
Public Sub New (validOn As AttributeTargets)
Parâmetros
- validOn
- AttributeTargets
O conjunto de valores combinados usando uma operação bit a bit OR para indicar quais os elementos do programa válidos.
Exemplos
A definição do atributo DispId ilustra a utilização de uma operação OR bit a bit para combinar vários AttributeTargets valores.
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
Observações
Pode combinar vários AttributeTargets valores usando uma operação bit a bit OR para obter a combinação desejada de elementos válidos do programa.
Para valores padrão de propriedades, veja os ValidOn, AllowMultiple, e Inherited as propriedades.