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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="EditorAttribute.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.    
  20.     using System.Diagnostics;
  21.     using System.Globalization;
  22.     using System.Security.Permissions;
  23.    
  24.     /// <devdoc>
  25.     /// <para>Specifies the editor to use to change a property. This class cannot be inherited.</para>
  26.     /// </devdoc>
  27.     [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
  28.     public sealed class EditorAttribute : Attribute
  29.     {
  30.        
  31.         private string baseTypeName;
  32.         private string typeName;
  33.         private string typeId;
  34.        
  35.         /// <devdoc>
  36.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class with the default editor, which is
  37.         /// no editor.</para>
  38.         /// </devdoc>
  39.         public EditorAttribute()
  40.         {
  41.             this.typeName = string.Empty;
  42.             this.baseTypeName = string.Empty;
  43.         }
  44.        
  45.         /// <devdoc>
  46.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class with the type name and base type
  47.         /// name of the editor.</para>
  48.         /// </devdoc>
  49.         public EditorAttribute(string typeName, string baseTypeName)
  50.         {
  51.             string temp = typeName.ToUpper(CultureInfo.InvariantCulture);
  52.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
  53.             this.typeName = typeName;
  54.             this.baseTypeName = baseTypeName;
  55.         }
  56.        
  57.         /// <devdoc>
  58.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.</para>
  59.         /// </devdoc>
  60.         public EditorAttribute(string typeName, Type baseType)
  61.         {
  62.             string temp = typeName.ToUpper(CultureInfo.InvariantCulture);
  63.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
  64.             this.typeName = typeName;
  65.             this.baseTypeName = baseType.AssemblyQualifiedName;
  66.         }
  67.        
  68.         /// <devdoc>
  69.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/>
  70.         /// class.</para>
  71.         /// </devdoc>
  72.         public EditorAttribute(Type type, Type baseType)
  73.         {
  74.             this.typeName = type.AssemblyQualifiedName;
  75.             this.baseTypeName = baseType.AssemblyQualifiedName;
  76.         }
  77.        
  78.         /// <devdoc>
  79.         /// <para>Gets the name of the base class or interface serving as a lookup key for this editor.</para>
  80.         /// </devdoc>
  81.         public string EditorBaseTypeName {
  82.             get { return baseTypeName; }
  83.         }
  84.        
  85.         /// <devdoc>
  86.         /// <para>Gets the name of the editor class.</para>
  87.         /// </devdoc>
  88.         public string EditorTypeName {
  89.             get { return typeName; }
  90.         }
  91.        
  92.         /// <internalonly/>
  93.         /// <devdoc>
  94.         /// <para>
  95.         /// This defines a unique ID for this attribute type. It is used
  96.         /// by filtering algorithms to identify two attributes that are
  97.         /// the same type. For most attributes, this just returns the
  98.         /// Type instance for the attribute. EditorAttribute overrides
  99.         /// this to include the type of the editor base type.
  100.         /// </para>
  101.         /// </devdoc>
  102.         public override object TypeId {
  103.             get {
  104.                 if (typeId == null) {
  105.                     string baseType = baseTypeName;
  106.                     int comma = baseType.IndexOf(',');
  107.                     if (comma != -1) {
  108.                         baseType = baseType.Substring(0, comma);
  109.                     }
  110.                     typeId = GetType().FullName + baseType;
  111.                 }
  112.                 return typeId;
  113.             }
  114.         }
  115.        
  116.         public override bool Equals(object obj)
  117.         {
  118.             if (obj == this) {
  119.                 return true;
  120.             }
  121.            
  122.             EditorAttribute other = obj as EditorAttribute;
  123.            
  124.             return (other != null) && other.typeName == typeName && other.baseTypeName == baseTypeName;
  125.         }
  126.        
  127.         public override int GetHashCode()
  128.         {
  129.             return base.GetHashCode();
  130.         }
  131.     }
  132. }

Developer Fusion