DescriptionAttribute Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger en beskrivning för en egenskap eller händelse.
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
- Arv
- Härledda
- Attribut
Exempel
I följande exempel skapas egenskapen MyImage . Egenskapen har två attribut, en DescriptionAttribute och en 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
I nästa exempel hämtas beskrivningen av MyImage. Först hämtar koden en PropertyDescriptorCollection med alla egenskaper för objektet. Därefter indexerar den till PropertyDescriptorCollection för att hämta MyImage. Sedan returneras attributen för den här egenskapen och sparas i attributvariabeln.
Exemplet skriver sedan ut beskrivningen genom att DescriptionAttribute hämta från AttributeCollection, och skriva den till konsolskärmen.
// 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)
Kommentarer
En visuell designer kan visa den angivna beskrivningen när du refererar till komponentmedlemmen, till exempel i en Properties window. Anropa Description för att komma åt värdet för det här attributet.
Mer information finns i Attribut.
Konstruktorer
| Name | Description |
|---|---|
| DescriptionAttribute() |
Initierar en ny instans av DescriptionAttribute klassen utan parametrar. |
| DescriptionAttribute(String) |
Initierar en ny instans av DescriptionAttribute klassen med en beskrivning. |
Fält
| Name | Description |
|---|---|
| Default |
Anger standardvärdet för DescriptionAttribute, som är en tom sträng (""). Det här |
Egenskaper
| Name | Description |
|---|---|
| Description |
Hämtar beskrivningen som lagras i det här attributet. |
| DescriptionValue |
Hämtar eller anger strängen som lagras som beskrivning. |
| TypeId |
När den implementeras i en härledd klass hämtar du en unik identifierare för den här Attribute. (Ärvd från Attribute) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Returnerar om värdet för det angivna objektet är lika med det aktuella DescriptionAttribute. |
| GetHashCode() |
Returnerar hash-koden för den här instansen. |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| IsDefaultAttribute() |
Returnerar ett värde som anger om detta är standardinstansen DescriptionAttribute . |
| IsDefaultAttribute() |
När den åsidosättas i en härledd klass anger du om värdet för den här instansen är standardvärdet för den härledda klassen. (Ärvd från Attribute) |
| Match(Object) |
När den åsidosätts i en härledd klass returneras ett värde som anger om den här instansen är lika med ett angivet objekt. (Ärvd från Attribute) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Explicita gränssnittsimplementeringar
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mappar en uppsättning namn till en motsvarande uppsättning av sändningsidentifierare. (Ärvd från Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Hämtar typinformationen för ett objekt, som kan användas för att hämta typinformationen för ett gränssnitt. (Ärvd från Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Hämtar antalet typinformationsgränssnitt som ett objekt tillhandahåller (antingen 0 eller 1). (Ärvd från Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Ger åtkomst till egenskaper och metoder som exponeras av ett objekt. (Ärvd från Attribute) |