DescriptionAttribute Osztály

Definíció

Megadja egy tulajdonság vagy esemény leírását.

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
Öröklődés
DescriptionAttribute
Származtatott
Attribútumok

Példák

Az alábbi példa létrehozza a tulajdonságot MyImage . A tulajdonság két attribútummal rendelkezik, az a DescriptionAttribute és 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

A következő példa lekéri a leírást MyImage. Először a kód lekéri PropertyDescriptorCollection az objektum összes tulajdonságát. Ezután indexel a PropertyDescriptorCollection lekéréshez MyImage. Ezután visszaadja a tulajdonság attribútumait, és menti őket az attribútumváltozóba.

A példa ezután kinyomtatja a leírást a lekéréssel DescriptionAttribute és a AttributeCollectionkonzolképernyőre való írással.

// 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)

Megjegyzések

A vizualizációtervező megjelenítheti a megadott leírást, amikor az összetevő tagra hivatkozik, például egy Tulajdonságok ablak. Hívás Description az attribútum értékének eléréséhez.

További információ: Attribútumok.

Konstruktorok

Name Description
DescriptionAttribute()

Inicializálja az DescriptionAttribute osztály új példányát paraméterek nélkül.

DescriptionAttribute(String)

Inicializálja az DescriptionAttribute osztály új példányát egy leírással.

Mezők

Name Description
Default

Az üres sztring ("") alapértelmezett értékét DescriptionAttributeadja meg. Ez static a mező írásvédett.

Tulajdonságok

Name Description
Description

Lekéri az attribútumban tárolt leírást.

DescriptionValue

Lekéri vagy beállítja a leírásként tárolt sztringet.

TypeId

Ha származtatott osztályban implementálják, ehhez egy egyedi azonosítót Attributekap.

(Öröklődés forrása Attribute)

Metódusok

Name Description
Equals(Object)

Azt adja vissza, hogy az adott objektum értéke megegyezik-e az aktuális DescriptionAttributeértékkel.

GetHashCode()

A példány kivonatkódját adja vissza.

GetType()

Lekéri az Type aktuális példányt.

(Öröklődés forrása Object)
IsDefaultAttribute()

Egy értéket ad vissza, amely jelzi, hogy ez-e az alapértelmezett DescriptionAttribute példány.

IsDefaultAttribute()

Ha egy származtatott osztályban felül van bírálva, azt jelzi, hogy a példány értéke-e a származtatott osztály alapértelmezett értéke.

(Öröklődés forrása Attribute)
Match(Object)

Származtatott osztály felülírásakor egy olyan értéket ad vissza, amely jelzi, hogy ez a példány egy adott objektummal egyenlő-e.

(Öröklődés forrása Attribute)
MemberwiseClone()

Az aktuális Objectpéldány sekély másolatát hozza létre.

(Öröklődés forrása Object)
ToString()

Az aktuális objektumot jelképező sztringet ad vissza.

(Öröklődés forrása Object)

Explicit interfész-implementációk

Name Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Névkészletet képez le a küldési azonosítók megfelelő készletére.

(Öröklődés forrása Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Lekéri egy objektum típusadatait, amelyek a felület típusadatainak lekérésére használhatók.

(Öröklődés forrása Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Lekéri az objektumok által biztosított típusinformációs felületek számát (0 vagy 1).

(Öröklődés forrása Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Hozzáférést biztosít az objektumok által közzétett tulajdonságokhoz és metódusokhoz.

(Öröklődés forrása Attribute)

A következőre érvényes:

Lásd még