The Labs \ Source Viewer \ SSCLI \ System.ComponentModel \ DisplayNameAttribute

  1. //------------------------------------------------------------------------------
  2. // <copyright file="DisplayNameAttribute.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*
  16. */
  17. namespace System.ComponentModel
  18. {
  19.     using System;
  20.     using System.Diagnostics;
  21.     using System.Security.Permissions;
  22.    
  23.     /// <devdoc>
  24.     /// <para>Specifies the display name for a property or event. The default is the name of the property or event.</para>
  25.     /// </devdoc>
  26.     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
  27.     [AttributeUsage(AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Class | AttributeTargets.Method)]
  28.     public class DisplayNameAttribute : Attribute
  29.     {
  30.         /// <devdoc>
  31.         /// <para>Specifies the default value for the <see cref='System.ComponentModel.DisplayNameAttribute'/> , which is an
  32.         /// empty string (""). This <see langword='static'/> field is read-only.</para>
  33.         /// </devdoc>
  34.         public static readonly DisplayNameAttribute Default = new DisplayNameAttribute();
  35.         private string _displayName;
  36.        
  37.         /// <devdoc>
  38.         /// <para>[To be supplied.]</para>
  39.         /// </devdoc>
  40.         public DisplayNameAttribute() : this(string.Empty)
  41.         {
  42.         }
  43.        
  44.         /// <devdoc>
  45.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.DisplayNameAttribute'/> class.</para>
  46.         /// </devdoc>
  47.         public DisplayNameAttribute(string displayName)
  48.         {
  49.             this._displayName = displayName;
  50.         }
  51.        
  52.         /// <devdoc>
  53.         /// <para>Gets the description stored in this attribute.</para>
  54.         /// </devdoc>
  55.         public virtual string DisplayName {
  56.             get { return DisplayNameValue; }
  57.         }
  58.        
  59.         /// <devdoc>
  60.         /// Read/Write property that directly modifies the string stored
  61.         /// in the description attribute. The default implementation
  62.         /// of the Description property simply returns this value.
  63.         /// </devdoc>
  64.         protected string DisplayNameValue {
  65.             get { return _displayName; }
  66.             set { _displayName = value; }
  67.         }
  68.        
  69.         public override bool Equals(object obj)
  70.         {
  71.             if (obj == this) {
  72.                 return true;
  73.             }
  74.            
  75.             DisplayNameAttribute other = obj as DisplayNameAttribute;
  76.            
  77.             return (other != null) && other.DisplayName == DisplayName;
  78.         }
  79.        
  80.         public override int GetHashCode()
  81.         {
  82.             return DisplayName.GetHashCode();
  83.         }
  84.        
  85.         /// <internalonly/>
  86.         /// <devdoc>
  87.         /// </devdoc>
  88.         public override bool IsDefaultAttribute()
  89.         {
  90.             return (this.Equals(Default));
  91.         }
  92.        
  93.     }
  94. }

Developer Fusion