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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="DesignerCategoryAttribute.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;
  21.     using System.ComponentModel;
  22.     using System.Security.Permissions;
  23.    
  24.     /// <devdoc>
  25.     /// <para>Specifies that the designer for a class belongs to a certain
  26.     /// category.</para>
  27.     /// </devdoc>
  28.     [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
  29.     public sealed class DesignerCategoryAttribute : Attribute
  30.     {
  31.         private string category;
  32.         private string typeId;
  33.        
  34.         /// <devdoc>
  35.         /// <para>
  36.         /// Specifies that a component marked with this category uses a
  37.         /// component designer. This <see langword='static '/>field is read-only.
  38.         /// </para>
  39.         /// </devdoc>
  40.         public static readonly DesignerCategoryAttribute Component = new DesignerCategoryAttribute("Component");
  41.        
  42.         /// <devdoc>
  43.         /// <para>
  44.         /// Specifies that a component marked with this category cannot use a visual
  45.         /// designer. This <see langword='static '/>field is read-only.
  46.         /// </para>
  47.         /// </devdoc>
  48.         public static readonly DesignerCategoryAttribute Default = new DesignerCategoryAttribute();
  49.        
  50.         /// <devdoc>
  51.         /// <para>
  52.         /// Specifies that a component marked with this category uses a form designer.
  53.         /// This <see langword='static '/>field is read-only.
  54.         /// </para>
  55.         /// </devdoc>
  56.         public static readonly DesignerCategoryAttribute Form = new DesignerCategoryAttribute("Form");
  57.        
  58.         /// <devdoc>
  59.         /// <para>
  60.         /// Specifies that a component marked with this category uses a generic designer.
  61.         /// This <see langword='static '/>field is read-only.
  62.         /// </para>
  63.         /// </devdoc>
  64.         public static readonly DesignerCategoryAttribute Generic = new DesignerCategoryAttribute("Designer");
  65.        
  66.         /// <devdoc>
  67.         /// <para>
  68.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerCategoryAttribute'/> class with the
  69.         /// default category.
  70.         /// </para>
  71.         /// </devdoc>
  72.         public DesignerCategoryAttribute()
  73.         {
  74.             category = string.Empty;
  75.         }
  76.        
  77.         /// <devdoc>
  78.         /// <para>
  79.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignerCategoryAttribute'/> class with
  80.         /// the given category name.
  81.         /// </para>
  82.         /// </devdoc>
  83.         public DesignerCategoryAttribute(string category)
  84.         {
  85.             this.category = category;
  86.         }
  87.        
  88.         /// <devdoc>
  89.         /// <para>
  90.         /// Gets the name of the category.
  91.         /// </para>
  92.         /// </devdoc>
  93.         public string Category {
  94.             get { return category; }
  95.         }
  96.        
  97.         /// <internalonly/>
  98.         /// <devdoc>
  99.         /// <para>
  100.         /// This defines a unique ID for this attribute type. It is used
  101.         /// by filtering algorithms to identify two attributes that are
  102.         /// the same type. For most attributes, this just returns the
  103.         /// Type instance for the attribute. DesignerAttribute overrides
  104.         /// this to include the name of the category
  105.         /// </para>
  106.         /// </devdoc>
  107.         public override object TypeId {
  108.             get {
  109.                 if (typeId == null) {
  110.                     typeId = GetType().FullName + Category;
  111.                 }
  112.                 return typeId;
  113.             }
  114.         }
  115.        
  116.        
  117.         /// <devdoc>
  118.         /// </devdoc>
  119.         /// <devdoc>
  120.         /// </devdoc>
  121.         /// <internalonly/>
  122.         /// <internalonly/>
  123.         public override bool Equals(object obj)
  124.         {
  125.             if (obj == this) {
  126.                 return true;
  127.             }
  128.            
  129.             DesignerCategoryAttribute other = obj as DesignerCategoryAttribute;
  130.             return (other != null) && other.category == category;
  131.         }
  132.        
  133.         /// <devdoc>
  134.         /// <para>[To be supplied.]</para>
  135.         /// </devdoc>
  136.         public override int GetHashCode()
  137.         {
  138.             return category.GetHashCode();
  139.         }
  140.        
  141.         /// <devdoc>
  142.         /// </devdoc>
  143.         /// <devdoc>
  144.         /// </devdoc>
  145.         /// <internalonly/>
  146.         /// <internalonly/>
  147.         public override bool IsDefaultAttribute()
  148.         {
  149.             return category.Equals(Default.Category);
  150.         }
  151.     }
  152. }

Developer Fusion