Attribute 构造函数

初始化 Attribute 类的新实例。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Protected Sub New
用法
Dim instance As New Attribute
protected Attribute ()
protected:
Attribute ()
protected Attribute ()
protected function Attribute ()

备注

此构造函数仅由从 Attribute 派生的类调用。

示例

下面的代码示例演示如何使用构造函数定义自定义参数 Attribute 类。

' 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  

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Attribute 类
Attribute 成员
System 命名空间