Export (0) Print
Expand All

Attribute Constructor

Initializes a new instance of the Attribute class.

[Visual Basic]
Protected Sub New()
[C#]
protected Attribute();
[C++]
protected: Attribute();
[JScript]
protected function Attribute();

Remarks

This constructor is only called by classes that derive from Attribute.

Example

[Visual Basic, C#, C++] The following code example shows the definition of a custom parameter attribute class with its constructor.

[Visual Basic] 
' 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 ' New

    ' 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 ' ArgumentUsageAttribute 

[C#] 
// 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; }
    }
}

[C++] 
// Define a custom parameter attribute that takes a single message argument.
[attribute( Parameter )]
public __gc class ArgumentUsageAttribute : public Attribute
{
    // usageMsg is storage for the attribute message.
    protected: 
        String* usageMsg;

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

        // This is the Message property for the attribute.
        __property String* get_Message( )
        {
            return usageMsg;
        }
        __property void set_Message( String* value )
        {
            this->usageMsg = value; 
        }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Attribute Class | Attribute Members | System Namespace

Show:
© 2014 Microsoft