共用方式為


HOW TO:將中繼資料提供給元件屬性、方法及事件

更新:2007 年 11 月

您可以使用屬性 (Attribute) 將說明中繼資料附加至您的屬性 (Property)、方法及事件。屬性 (Attribute) 是一種可修改程式碼項目的特定類別,會在編譯時期發出至這些程式碼項目的中繼資料。設計階段屬性 (Attribute) 則是與開發環境互動,提供開發人員有關您元件的資訊。常用屬性的範例是 DescriptionAttribute。當附加至屬性 (Property) 或事件時,DescriptionAttribute 屬性 (Attribute) 會在 [屬性] 視窗中顯示一個簡短字串。如以下範例所示:

Imports System.ComponentModel
<Description("This property specifies the active Widget")> Public _
   Property ActiveWidget as Widget
' Insert code to implementat functionality.
End Property
using System.ComponentModel;
[Description("This property specifies the active Widget")]
public Widget ActiveWidget
{
   // Insert code to implementat functionality.
}

如需可用來加強您元件設計階段支援的屬性 (Attribute) 詳細資訊,請參閱元件的設計階段屬性

如需將屬性 (Attribute) 附加至屬性 (Property)、方法或事件

  • 將屬性 (Attribute) 建構函式的呼叫加入至您要修改的程式碼項目。加入這個呼叫的方式是將其置於角括弧 <> (Visual Basic) 或方括號 [] (C#) 內,然後置放在您要修改的程式碼項目之前。

    <Browsable(False)> Public Property ServingSize as Integer
    
    [Browsable(false)]
    public int ServingSize
    

請參閱

工作

HOW TO:提供關於元件的中繼資料描述

概念

元件的設計階段屬性

存取自訂屬性

擷取儲存於屬性中的資訊

參考

Attribute

其他資源

元件的使用者協助