DescriptionAttribute 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定属性或事件的说明。
public ref class DescriptionAttribute : Attribute[System.AttributeUsage(System.AttributeTargets.All)]
public class DescriptionAttribute : Attributepublic class DescriptionAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.All)>]
type DescriptionAttribute = class
    inherit Attributetype DescriptionAttribute = class
    inherit AttributePublic Class DescriptionAttribute
Inherits Attribute- 继承
- 派生
- 属性
示例
以下示例创建 属性 MyImage 。 属性具有两个CategoryAttribute属性:和 DescriptionAttribute 。
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
下一个示例获取 的说明 MyImage。 首先,代码获取具有 PropertyDescriptorCollection 对象的所有属性的 。 接下来,它会索引到 中 PropertyDescriptorCollection 以获取 MyImage。 然后,它将返回此属性的属性,并将其保存在 attributes 变量中。
然后,该示例通过从 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 的默认值,即空字符串 ("")。 此  | 
属性
| Description | 获取存储在此属性 (Attribute) 中的说明。 | 
| 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) |