Attribute-Konstruktor
Initialisiert eine neue Instanz der Attribute-Klasse.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Protected Sub New
'Usage
Dim instance As New Attribute
protected Attribute ()
protected:
Attribute ()
protected Attribute ()
protected function Attribute ()
Hinweise
Dieser Konstruktor wird nur von Klassen aufgerufen, die von Attribute abgeleitet sind.
Beispiel
Im folgenden Codebeispiel wird die Definition der Attribute-Klasse eines benutzerdefinierten Parameters und ihres Konstruktors veranschaulicht.
' 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
// 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 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.
/** @attribute AttributeUsage(AttributeTargets.Parameter)
*/
public class ArgumentUsageAttribute extends Attribute
{
// This is the attribute constructor.
public ArgumentUsageAttribute(String usgMsg)
{
this.usageMsg = usgMsg;
} //ArgumentUsageAttribute
// usageMsg is storage for the attribute message.
protected String usageMsg;
// This is the Message property for the attribute.
/** @property
*/
public String get_Message()
{
return usageMsg;
} //get_Message
/** @property
*/
public void set_Message(String value)
{
usageMsg = value;
} //set_Message
} //ArgumentUsageAttribute
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0