Attribute Конструктор

Определение

Инициализирует новый экземпляр класса Attribute.Initializes a new instance of the Attribute class.

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

Примеры

В следующем примере кода показано определение пользовательского параметра класса Attribute со своим конструктором.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

Комментарии

Этот конструктор вызывается только классами, производными от Attribute.This constructor is only called by classes that derive from Attribute.

Применяется к