mscorlib(4.0.0.0) API with additions
DisplayNameAttribute.cs
1 namespace System.ComponentModel
2 {
4  [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event)]
6  {
8  public static readonly DisplayNameAttribute Default = new DisplayNameAttribute();
9 
10  private string _displayName;
11 
14  public virtual string DisplayName => DisplayNameValue;
15 
18  protected string DisplayNameValue
19  {
20  get
21  {
22  return _displayName;
23  }
24  set
25  {
26  _displayName = value;
27  }
28  }
29 
32  : this(string.Empty)
33  {
34  }
35 
38  public DisplayNameAttribute(string displayName)
39  {
40  _displayName = displayName;
41  }
42 
47  public override bool Equals(object obj)
48  {
49  if (obj == this)
50  {
51  return true;
52  }
53  DisplayNameAttribute displayNameAttribute = obj as DisplayNameAttribute;
54  if (displayNameAttribute != null)
55  {
56  return displayNameAttribute.DisplayName == DisplayName;
57  }
58  return false;
59  }
60 
63  public override int GetHashCode()
64  {
65  return DisplayName.GetHashCode();
66  }
67 
71  public override bool IsDefaultAttribute()
72  {
73  return Equals(Default);
74  }
75  }
76 }
override bool Equals(object obj)
Determines whether two T:System.ComponentModel.DisplayNameAttribute instances are equal.
Represents the base class for custom attributes.
Definition: Attribute.cs:15
DisplayNameAttribute()
Initializes a new instance of the T:System.ComponentModel.DisplayNameAttribute class.
static readonly DisplayNameAttribute Default
Specifies the default value for the T:System.ComponentModel.DisplayNameAttribute. This field is read-...
virtual string DisplayName
Gets the display name for a property, event, or public void method that takes no arguments stored in ...
DisplayNameAttribute(string displayName)
Initializes a new instance of the T:System.ComponentModel.DisplayNameAttribute class using the displa...
string DisplayNameValue
Gets or sets the display name.
AttributeTargets
Specifies the application elements on which it is valid to apply an attribute.
Specifies the display name for a property, event, or public void method which takes no arguments.
override int GetHashCode()
Returns the hash code for this instance.
override bool IsDefaultAttribute()
Determines if this attribute is the default.