DescriptionAttribute Class
TOC
Collapse the table of content
Expand the table of content

DescriptionAttribute Class

 

Specifies a description for a property or event.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)


[AttributeUsageAttribute(AttributeTargets::All)]
public ref class DescriptionAttribute : Attribute

NameDescription
System_CAPS_pubmethodDescriptionAttribute()

Initializes a new instance of the DescriptionAttribute class with no parameters.

System_CAPS_pubmethodDescriptionAttribute(String^)

Initializes a new instance of the DescriptionAttribute class with a description.

NameDescription
System_CAPS_pubpropertyDescription

Gets the description stored in this attribute.

System_CAPS_protpropertyDescriptionValue

Gets or sets the string stored as the description.

System_CAPS_pubpropertyTypeId

When implemented in a derived class, gets a unique identifier for this Attribute.(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object^)

Returns whether the value of the given object is equal to the current DescriptionAttribute.(Overrides Attribute::Equals(Object^).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides Attribute::GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

Returns a value indicating whether this is the default DescriptionAttribute instance.(Overrides Attribute::IsDefaultAttribute().)

System_CAPS_pubmethodMatch(Object^)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticDefault

Specifies the default value for the DescriptionAttribute, which is an empty string (""). This static field is read-only.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute::GetIDsOfNames(Guid%, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute::GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute::GetTypeInfoCount(UInt32%)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute::Invoke(UInt32, Guid%, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from Attribute.)

A visual designer can display the specified description when referencing the component member, such as in a Properties window. Call Description to access the value of this attribute.

For more information, see Extending Metadata Using Attributes.

The following example creates the MyImage property. 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.
      }
   }

The next example gets the description of MyImage. First the code gets a PropertyDescriptorCollection with all the properties for the object. Next it indexes into the PropertyDescriptorCollection to get MyImage. Then it returns the attributes for this property and saves them in the attributes variable.

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

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft