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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="InheritanceAttribute.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.Security.Permissions;
  21.    
  22.     /// <devdoc>
  23.     /// <para>Marks instances of objects that are inherited from their base class. This
  24.     /// class cannot be inherited.</para>
  25.     /// </devdoc>
  26.     [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event)]
  27.     public sealed class InheritanceAttribute : Attribute
  28.     {
  29.        
  30.         private readonly InheritanceLevel inheritanceLevel;
  31.        
  32.         /// <devdoc>
  33.         /// <para>
  34.         /// Specifies that the component is inherited. This field is
  35.         /// read-only.
  36.         /// </para>
  37.         /// </devdoc>
  38.         public static readonly InheritanceAttribute Inherited = new InheritanceAttribute(InheritanceLevel.Inherited);
  39.        
  40.         /// <devdoc>
  41.         /// <para>
  42.         /// Specifies that
  43.         /// the component is inherited and is read-only. This field is
  44.         /// read-only.
  45.         /// </para>
  46.         /// </devdoc>
  47.         public static readonly InheritanceAttribute InheritedReadOnly = new InheritanceAttribute(InheritanceLevel.InheritedReadOnly);
  48.        
  49.         /// <devdoc>
  50.         /// <para>
  51.         /// Specifies that the component is not inherited. This field is
  52.         /// read-only.
  53.         /// </para>
  54.         /// </devdoc>
  55.         public static readonly InheritanceAttribute NotInherited = new InheritanceAttribute(InheritanceLevel.NotInherited);
  56.        
  57.         /// <devdoc>
  58.         /// <para>
  59.         /// Specifies the default value for
  60.         /// the InheritanceAttribute as NotInherited.
  61.         /// </para>
  62.         /// </devdoc>
  63.         public static readonly InheritanceAttribute Default = NotInherited;
  64.        
  65.         /// <devdoc>
  66.         /// <para>Initializes a new instance of the System.ComponentModel.Design.InheritanceAttribute
  67.         /// class.</para>
  68.         /// </devdoc>
  69.         public InheritanceAttribute()
  70.         {
  71.             inheritanceLevel = Default.inheritanceLevel;
  72.         }
  73.        
  74.         /// <devdoc>
  75.         /// <para>Initializes a new instance of the System.ComponentModel.Design.InheritanceAttribute class
  76.         /// with the specified inheritance
  77.         /// level.</para>
  78.         /// </devdoc>
  79.         public InheritanceAttribute(InheritanceLevel inheritanceLevel)
  80.         {
  81.             this.inheritanceLevel = inheritanceLevel;
  82.         }
  83.        
  84.         /// <devdoc>
  85.         /// <para>
  86.         /// Gets or sets
  87.         /// the current inheritance level stored in this attribute.
  88.         /// </para>
  89.         /// </devdoc>
  90.         public InheritanceLevel InheritanceLevel {
  91.             get { return inheritanceLevel; }
  92.         }
  93.        
  94.         /// <devdoc>
  95.         /// <para>
  96.         /// Override to test for equality.
  97.         /// </para>
  98.         /// </devdoc>
  99.         public override bool Equals(object value)
  100.         {
  101.             if (value == this) {
  102.                 return true;
  103.             }
  104.            
  105.             if (!(value is InheritanceAttribute)) {
  106.                 return false;
  107.             }
  108.            
  109.             InheritanceLevel valueLevel = ((InheritanceAttribute)value).InheritanceLevel;
  110.             return (valueLevel == inheritanceLevel);
  111.         }
  112.        
  113.         /// <devdoc>
  114.         /// <para>
  115.         /// Returns the hashcode for this object.
  116.         /// </para>
  117.         /// </devdoc>
  118.         public override int GetHashCode()
  119.         {
  120.             return base.GetHashCode();
  121.         }
  122.        
  123.         /// <devdoc>
  124.         /// <para>
  125.         /// Gets whether this attribute is the default.
  126.         /// </para>
  127.         /// </devdoc>
  128.         public override bool IsDefaultAttribute()
  129.         {
  130.             return (this.Equals(Default));
  131.         }
  132.        
  133.         /// <devdoc>
  134.         /// <para>
  135.         /// Converts this attribute to a string.
  136.         /// </para>
  137.         /// </devdoc>
  138.         public override string ToString()
  139.         {
  140.             return TypeDescriptor.GetConverter(typeof(InheritanceLevel)).ConvertToString(InheritanceLevel);
  141.         }
  142.     }
  143. }

Developer Fusion