DescriptionAttribute Klasa
Definicja
Określa opis właściwości lub zdarzenia.Specifies a description for a property or event.
public ref class DescriptionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public class DescriptionAttribute : Attribute
public class DescriptionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type DescriptionAttribute = class
inherit Attribute
type DescriptionAttribute = class
inherit Attribute
Public Class DescriptionAttribute
Inherits Attribute
- Dziedziczenie
- Pochodne
- Atrybuty
Przykłady
Poniższy przykład tworzy MyImage
Właściwość.The following example creates the MyImage
property. Właściwość ma dwa atrybuty, DescriptionAttribute a i CategoryAttribute .The property has two attributes, a DescriptionAttribute and 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.
return 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
Następny przykład Pobiera opis MyImage
.The next example gets the description of MyImage
. Pierwszy kod pobiera PropertyDescriptorCollection wszystkie właściwości obiektu.First the code gets a PropertyDescriptorCollection with all the properties for the object. Następnie indeksuje element PropertyDescriptorCollection do get MyImage
.Next it indexes into the PropertyDescriptorCollection to get MyImage
. Następnie zwraca atrybuty dla tej właściwości i zapisuje je w zmiennej atrybutów.Then it returns the attributes for this property and saves them in the attributes variable.
Następnie w przykładzie jest drukowany opis przez pobranie DescriptionAttribute z AttributeCollection i zapisanie go na ekranie konsoli.The example then prints the description by retrieving DescriptionAttribute from the AttributeCollection, and writing it to the console screen.
// 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)
Uwagi
Projektant wizualny może wyświetlić określony opis podczas odwoływania się do elementu członkowskiego składnika, takiego jak w okno Właściwości.A visual designer can display the specified description when referencing the component member, such as in a Properties window. Wywołaj Description , aby uzyskać dostęp do wartości tego atrybutu.Call Description to access the value of this attribute.
Aby uzyskać więcej informacji, zobacz atrybuty.For more information, see Attributes.
Konstruktory
DescriptionAttribute() |
Inicjuje nowe wystąpienie DescriptionAttribute klasy bez parametrów.Initializes a new instance of the DescriptionAttribute class with no parameters. |
DescriptionAttribute(String) |
Inicjuje nowe wystąpienie DescriptionAttribute klasy z opisem.Initializes a new instance of the DescriptionAttribute class with a description. |
Pola
Default |
Określa wartość domyślną DescriptionAttribute , która jest ciągiem pustym ("").Specifies the default value for the DescriptionAttribute, which is an empty string (""). To |
Właściwości
Description |
Pobiera opis przechowywany w tym atrybucie.Gets the description stored in this attribute. |
DescriptionValue |
Pobiera lub ustawia ciąg przechowywany jako opis.Gets or sets the string stored as the description. |
TypeId |
Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego elementu Attribute .When implemented in a derived class, gets a unique identifier for this Attribute. (Odziedziczone po Attribute) |
Metody
Equals(Object) |
Zwraca czy wartość danego obiektu jest równa bieżącemu DescriptionAttribute .Returns whether the value of the given object is equal to the current DescriptionAttribute. |
GetHashCode() |
Zwraca wartość skrótu dla tego wystąpienia.Returns the hash code for this instance. |
GetType() |
Pobiera Type bieżące wystąpienie.Gets the Type of the current instance. (Odziedziczone po Object) |
IsDefaultAttribute() |
Zwraca wartość wskazującą, czy jest to wystąpienie domyślne DescriptionAttribute .Returns a value indicating whether this is the default DescriptionAttribute instance. |
IsDefaultAttribute() |
Gdy jest zastępowany w klasie pochodnej, wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Odziedziczone po Attribute) |
Match(Object) |
Gdy jest zastępowany w klasie pochodnej, zwraca wartość wskazującą, czy to wystąpienie jest zgodne z określonym obiektem.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Odziedziczone po Attribute) |
MemberwiseClone() |
Tworzy skróconą kopię bieżącego elementu Object .Creates a shallow copy of the current Object. (Odziedziczone po Object) |
ToString() |
Zwraca ciąg reprezentujący bieżący obiekt.Returns a string that represents the current object. (Odziedziczone po Object) |
Jawne implementacje interfejsu
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.Maps a set of names to a corresponding set of dispatch identifiers. (Odziedziczone po Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Pobiera informacje o typie dla obiektu, którego można użyć do uzyskania informacji o typie dla interfejsu.Retrieves the type information for an object, which can be used to get the type information for an interface. (Odziedziczone po Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Odziedziczone po Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.Provides access to properties and methods exposed by an object. (Odziedziczone po Attribute) |