Attribute Konstruktor

Definition

Initialisiert eine neue Instanz der Attribute-Klasse.Initializes a new instance of the Attribute class.

protected:
 Attribute();
protected Attribute ();
Protected Sub New ()

Beispiele

Das folgende Codebeispiel zeigt die Definition eines benutzerdefinierten Parameters Attribute-Klasse mit dessen Konstruktor.The following code example shows the definition of a custom parameter Attribute class with its constructor.

// Define a custom parameter attribute that takes a single message argument.

[AttributeUsage(AttributeTargets::Parameter)]
public ref class ArgumentUsageAttribute: public Attribute
{
protected:

   // usageMsg is storage for the attribute message.
   String^ usageMsg;

public:

   // This is the attribute constructor.
   ArgumentUsageAttribute( String^ UsageMsg )
   {
      this->usageMsg = UsageMsg;
   }


   property String^ Message 
   {
      // This is the Message property for the attribute.
      String^ get()
      {
         return usageMsg;
      }

      void set( String^ value )
      {
         this->usageMsg = value;
      }
   }
};
// Define a custom parameter attribute that takes a single message argument.
[AttributeUsage( AttributeTargets.Parameter )]
public class ArgumentUsageAttribute : Attribute
{
    // This is the attribute constructor.
    public ArgumentUsageAttribute( string UsageMsg )
    {
        this.usageMsg = UsageMsg;
    }

    // usageMsg is storage for the attribute message.
    protected string usageMsg;

    // This is the Message property for the attribute.
    public string Message
    {
        get { return usageMsg; }
        set { usageMsg = value; }
    }
}
' Define a custom parameter attribute that takes a single message argument.
<AttributeUsage(AttributeTargets.Parameter)>  _
Public Class ArgumentUsageAttribute
    Inherits Attribute
       
    ' This is the attribute constructor.
    Public Sub New(UsageMsg As String)
        Me.usageMsg = UsageMsg
    End Sub

    ' usageMsg is storage for the attribute message.
    Protected usageMsg As String
       
    ' This is the Message property for the attribute.
    Public Property Message() As String
        Get
            Return usageMsg
        End Get
        Set
            usageMsg = value
        End Set
    End Property
End Class

Hinweise

Dieser Konstruktor wird nur von Klassen aufgerufen, die von Attribute abgeleitet werden.This constructor is only called by classes that derive from Attribute.

Gilt für: