AttributeUsageAttribute(AttributeTargets) Constructeur

Définition

Initialise une nouvelle instance de la AttributeUsageAttribute classe avec la liste spécifiée de AttributeTargets, la AllowMultiple valeur et la Inherited valeur.

public:
 AttributeUsageAttribute(AttributeTargets validOn);
public AttributeUsageAttribute(AttributeTargets validOn);
new AttributeUsageAttribute : AttributeTargets -> AttributeUsageAttribute
Public Sub New (validOn As AttributeTargets)

Paramètres

validOn
AttributeTargets

Ensemble de valeurs combinées à l’aide d’une opération OR au niveau du bit pour indiquer quels éléments de programme sont valides.

Exemples

La définition de l’attribut DispId illustre l’utilisation d’une opération OR au niveau du bit pour combiner plusieurs AttributeTargets valeurs.

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

Remarques

Vous pouvez combiner plusieurs AttributeTargets valeurs à l’aide d’une opération OR au niveau du bit pour obtenir la combinaison souhaitée d’éléments de programme valides.

Pour connaître les valeurs de propriété par défaut, consultez les propriétés , ValidOnet AllowMultiple les Inheritedpropriétés.

S’applique à

Voir aussi