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 プロパティを作成します。 プロパティには、 DescriptionAttributeCategoryAttributeの 2 つの属性があります。

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の説明を取得します。 まず、コードはオブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。 次に、PropertyDescriptorCollectionを取得するためにMyImageにインデックスを作成します。 次に、このプロパティの属性を返し、属性変数に保存します。

次に、AttributeCollectionからDescriptionAttributeを取得し、コンソール画面に書き込んで説明を出力します。

// 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を呼び出して、この属性の値にアクセスします。

詳細については、「属性」を参照してください。

コンストラクター

名前 説明
DescriptionAttribute()

パラメーターを指定せず、 DescriptionAttribute クラスの新しいインスタンスを初期化します。

DescriptionAttribute(String)

説明を使用して、 DescriptionAttribute クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
Default

空の文字列 ("") である DescriptionAttributeの既定値を指定します。 この static フィールドは読み取り専用です。

プロパティ

名前 説明
Description

この属性に格納されている説明を取得します。

DescriptionValue

説明として格納される文字列を取得または設定します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

指定したオブジェクトの値が現在の DescriptionAttributeと等しいかどうかを返します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

これが既定の DescriptionAttribute インスタンスであるかどうかを示す値を返します。

IsDefaultAttribute()

派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください