DisplayNameAttribute 类

定义

指定不带参数的属性、事件或公共 void 方法的显示名称。

public ref class DisplayNameAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)]
public class DisplayNameAttribute : Attribute
public class DisplayNameAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Event | System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DisplayNameAttribute = class
    inherit Attribute
type DisplayNameAttribute = class
    inherit Attribute
Public Class DisplayNameAttribute
Inherits Attribute
继承
DisplayNameAttribute
属性

示例

下面的代码示例演示如何使用DisplayNameAttribute类更改控件中PropertyGrid调用MisnamedPropertyRenamedProperty的属性的名称。 有关完整代码列表,请参阅如何:在Windows Forms控件中应用属性

// This property exists only to demonstrate the
// DisplayName attribute. When this control
// is attached to a PropertyGrid control, the
// property will appear as "RenamedProperty"
// instead of "MisnamedProperty".
[Description("Demonstrates DisplayNameAttribute.")]
[DisplayName("RenamedProperty")]
public bool MisnamedProperty => true;
' This property exists only to demonstrate the 
' DisplayName attribute. When this control 
' is attached to a PropertyGrid control, the
' property will be appear as "RenamedProperty"
' instead of "MisnamedProperty".
<Description("Demonstrates DisplayNameAttribute."), _
DisplayName("RenamedProperty")> _
Public ReadOnly Property MisnamedProperty() As Boolean
    Get
        Return True
    End Get
End Property

注解

默认值为属性或事件的名称。 使用反射的默认实现 GetSortedActionItems 搜索不带参数的公共属性和公共 void 方法。 GetSortedActionItems DisplayNameAttribute搜索每个属性和方法,如果找到,则使用该字符串而不是属性或方法名称。

构造函数

名称 说明
DisplayNameAttribute()

初始化 DisplayNameAttribute 类的新实例。

DisplayNameAttribute(String)

使用显示名称初始化类的新实例 DisplayNameAttribute

字段

名称 说明
Default

指定 . 的 DisplayNameAttribute默认值。 此字段是只读的。

属性

名称 说明
DisplayName

获取属性、事件或公共 void 方法的显示名称,该方法不采用存储在此属性中的参数。

DisplayNameValue

获取或设置显示名称。

TypeId

在派生类中实现时,获取此 Attribute的唯一标识符。

(继承自 Attribute)

方法

名称 说明
Equals(Object)

确定两个 DisplayNameAttribute 实例是否相等。

GetHashCode()

返回此实例的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

确定此属性是否为默认值。

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)

适用于

另请参阅