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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="DesignerAttribute.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.ComponentModel;
  21.     using System.ComponentModel.Design;
  22.     using System.Diagnostics;
  23.     using System.Globalization;
  24.     using System.Security.Permissions;
  25.    
  26.     /// <devdoc>
  27.     /// <para>Specifies the class to use to implement design-time services.</para>
  28.     /// </devdoc>
  29.     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
  30.     public sealed class DesignerAttribute : Attribute
  31.     {
  32.         private readonly string designerTypeName;
  33.         private readonly string designerBaseTypeName;
  34.         private string typeId;
  35.        
  36.         /// <devdoc>
  37.         /// <para>
  38.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the name of the type that
  39.         /// provides design-time services.
  40.         /// </para>
  41.         /// </devdoc>
  42.         public DesignerAttribute(string designerTypeName)
  43.         {
  44.             string temp = designerTypeName.ToUpper(CultureInfo.InvariantCulture);
  45.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + designerTypeName + " . Please remove the .dll extension");
  46.             this.designerTypeName = designerTypeName;
  47.             this.designerBaseTypeName = typeof(IDesigner).FullName;
  48.         }
  49.        
  50.         /// <devdoc>
  51.         /// <para>
  52.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the type that provides
  53.         /// design-time services.
  54.         /// </para>
  55.         /// </devdoc>
  56.         public DesignerAttribute(Type designerType)
  57.         {
  58.             this.designerTypeName = designerType.AssemblyQualifiedName;
  59.             this.designerBaseTypeName = typeof(IDesigner).FullName;
  60.         }
  61.        
  62.         /// <devdoc>
  63.         /// <para>
  64.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the designer type and the
  65.         /// base class for the designer.
  66.         /// </para>
  67.         /// </devdoc>
  68.         public DesignerAttribute(string designerTypeName, string designerBaseTypeName)
  69.         {
  70.             string temp = designerTypeName.ToUpper(CultureInfo.InvariantCulture);
  71.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + designerTypeName + " . Please remove the .dll extension");
  72.             this.designerTypeName = designerTypeName;
  73.             this.designerBaseTypeName = designerBaseTypeName;
  74.         }
  75.        
  76.         /// <devdoc>
  77.         /// <para>
  78.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class, using the name of the designer
  79.         /// class and the base class for the designer.
  80.         /// </para>
  81.         /// </devdoc>
  82.         public DesignerAttribute(string designerTypeName, Type designerBaseType)
  83.         {
  84.             string temp = designerTypeName.ToUpper(CultureInfo.InvariantCulture);
  85.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + designerTypeName + " . Please remove the .dll extension");
  86.             this.designerTypeName = designerTypeName;
  87.             this.designerBaseTypeName = designerBaseType.AssemblyQualifiedName;
  88.         }
  89.        
  90.         /// <devdoc>
  91.         /// <para>
  92.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the types of the designer and
  93.         /// designer base class.
  94.         /// </para>
  95.         /// </devdoc>
  96.         public DesignerAttribute(Type designerType, Type designerBaseType)
  97.         {
  98.             this.designerTypeName = designerType.AssemblyQualifiedName;
  99.             this.designerBaseTypeName = designerBaseType.AssemblyQualifiedName;
  100.         }
  101.        
  102.         /// <devdoc>
  103.         /// <para>
  104.         /// Gets
  105.         /// the name of the base type of this designer.
  106.         /// </para>
  107.         /// </devdoc>
  108.         public string DesignerBaseTypeName {
  109.             get { return designerBaseTypeName; }
  110.         }
  111.        
  112.         /// <devdoc>
  113.         /// <para>
  114.         /// Gets the name of the designer type associated with this designer attribute.
  115.         /// </para>
  116.         /// </devdoc>
  117.         public string DesignerTypeName {
  118.             get { return designerTypeName; }
  119.         }
  120.        
  121.         /// <internalonly/>
  122.         /// <devdoc>
  123.         /// <para>
  124.         /// This defines a unique ID for this attribute type. It is used
  125.         /// by filtering algorithms to identify two attributes that are
  126.         /// the same type. For most attributes, this just returns the
  127.         /// Type instance for the attribute. DesignerAttribute overrides
  128.         /// this to include the type of the designer base type.
  129.         /// </para>
  130.         /// </devdoc>
  131.         public override object TypeId {
  132.             get {
  133.                 if (typeId == null) {
  134.                     string baseType = designerBaseTypeName;
  135.                     int comma = baseType.IndexOf(',');
  136.                     if (comma != -1) {
  137.                         baseType = baseType.Substring(0, comma);
  138.                     }
  139.                     typeId = GetType().FullName + baseType;
  140.                 }
  141.                 return typeId;
  142.             }
  143.         }
  144.        
  145.         public override bool Equals(object obj)
  146.         {
  147.             if (obj == this) {
  148.                 return true;
  149.             }
  150.            
  151.             DesignerAttribute other = obj as DesignerAttribute;
  152.            
  153.             return (other != null) && other.designerBaseTypeName == designerBaseTypeName && other.designerTypeName == designerTypeName;
  154.         }
  155.        
  156.         public override int GetHashCode()
  157.         {
  158.             return designerTypeName.GetHashCode() ^ designerBaseTypeName.GetHashCode();
  159.         }
  160.     }
  161. }

Developer Fusion