DescriptionAttribute 類別

定義

指定屬性或事件的描述。

public ref class DescriptionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class DescriptionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DescriptionAttribute = class
    inherit Attribute
Public Class DescriptionAttribute
Inherits Attribute
繼承
DescriptionAttribute
衍生
屬性

範例

以下範例會產生該 MyImage 性質。 該屬性有兩個屬性,a DescriptionAttribute 和 a CategoryAttribute

public:
   property Image^ MyImage 
   {
      [Description("The image associated with the control"),Category("Appearance")]
      Image^ get()
      {
         // Insert code here.
         return image1;
      }

      void set( Image^ value )
      {
         // Insert code here.
      }
   }
[Description("The image associated with the control"), Category("Appearance")]
public Image MyImage
{
    get =>
        // Insert code here.
        image1;
    set
    {
        // Insert code here.
    }
}
<Description("The image associated with the control"), _
    Category("Appearance")> _
Public Property MyImage() As Image
    Get
        ' Insert code here.
        Return image1
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

下一個例子描述 MyImage了。 首先,程式碼會取得包含物件所有屬性的 a PropertyDescriptorCollection 。 接著它會索引到 PropertyDescriptorCollection ,取得 MyImage。 接著它會回傳這個屬性的屬性,並儲存在屬性變數中。

範例接著從 擷取 DescriptionAttributeAttributeCollection,並寫入主控台畫面,列印描述。

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyImage" ]->Attributes;

/* Prints the description by retrieving the DescriptionAttribute 
      * from the AttributeCollection. */
DescriptionAttribute^ myAttribute = dynamic_cast<DescriptionAttribute^>(attributes[ DescriptionAttribute::typeid ]);
Console::WriteLine( myAttribute->Description );
// Gets the attributes for the property.
AttributeCollection attributes =
   TypeDescriptor.GetProperties(this)["MyImage"].Attributes;

/* Prints the description by retrieving the DescriptionAttribute 
 * from the AttributeCollection. */
DescriptionAttribute myAttribute =
   (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
Console.WriteLine(myAttribute.Description);
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
    TypeDescriptor.GetProperties(Me)("MyImage").Attributes

' Prints the description by retrieving the DescriptionAttribute
' from the AttributeCollection. 
Dim myAttribute As DescriptionAttribute = _
    CType(attributes(GetType(DescriptionAttribute)), DescriptionAttribute)
Console.WriteLine(myAttribute.Description)

備註

視覺化設計器可以在參考元件成員時顯示指定的描述,例如在 屬性視窗 中。 呼叫 Description 以存取此屬性的值。

如需詳細資訊,請參閱屬性

建構函式

名稱 Description
DescriptionAttribute()

初始化一個無參數的新類別實例 DescriptionAttribute

DescriptionAttribute(String)

初始化一個新的類別實例 DescriptionAttribute ,並附有描述。

欄位

名稱 Description
Default

指定 的預設值 DescriptionAttribute,該值為空字串(“”)。 此 static 欄位為唯讀。

屬性

名稱 Description
Description

將描述儲存在這個屬性中。

DescriptionValue

取得或設定儲存為描述的字串。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

回傳給定物件的值是否等於當前 DescriptionAttribute值。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

回傳一個值,表示此是否為預設 DescriptionAttribute 實例。

IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱