Attribute Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the Attribute class.
protected:
Attribute();
protected Attribute ();
Protected Sub New ()
Examples
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); AllowNullLiteral>]
type ArgumentUsageAttribute(usageMsg) =
inherit Attribute()
// This is the Message property for the attribute.
member val Message = usageMsg with get, set
' 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
Remarks
This constructor is only called by classes that derive from Attribute.
Applies to
Samarbeta med oss på GitHub
Källan för det här innehållet finns på GitHub, där du även kan skapa och granska ärenden och pull-begäranden. Se vår deltagarguide för mer information.