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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="DesignOnlyAttribute.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 whether a property can only be set at
  25.     /// design time.</para>
  26.     /// </devdoc>
  27.     [AttributeUsage(AttributeTargets.All)]
  28.     public sealed class DesignOnlyAttribute : Attribute
  29.     {
  30.         private bool isDesignOnly = false;
  31.        
  32.         /// <devdoc>
  33.         /// <para>
  34.         /// Initializes a new instance of the <see cref='System.ComponentModel.DesignOnlyAttribute'/> class.
  35.         /// </para>
  36.         /// </devdoc>
  37.         public DesignOnlyAttribute(bool isDesignOnly)
  38.         {
  39.             this.isDesignOnly = isDesignOnly;
  40.         }
  41.        
  42.         /// <devdoc>
  43.         /// <para>
  44.         /// Gets a value indicating whether a property
  45.         /// can be set only at design time.
  46.         /// </para>
  47.         /// </devdoc>
  48.         public bool IsDesignOnly {
  49.             get { return isDesignOnly; }
  50.         }
  51.        
  52.         /// <devdoc>
  53.         /// <para>
  54.         /// Specifies that a property can be set only at design time. This
  55.         /// <see langword='static '/>field is read-only.
  56.         /// </para>
  57.         /// </devdoc>
  58.         public static readonly DesignOnlyAttribute Yes = new DesignOnlyAttribute(true);
  59.        
  60.         /// <devdoc>
  61.         /// <para>
  62.         /// Specifies
  63.         /// that a
  64.         /// property can be set at design time or at run
  65.         /// time. This <see langword='static '/>field is read-only.
  66.         /// </para>
  67.         /// </devdoc>
  68.         public static readonly DesignOnlyAttribute No = new DesignOnlyAttribute(false);
  69.        
  70.         /// <devdoc>
  71.         /// <para>
  72.         /// Specifies the default value for the <see cref='System.ComponentModel.DesignOnlyAttribute'/>, which is <see cref='System.ComponentModel.DesignOnlyAttribute.No'/>. This <see langword='static'/> field is
  73.         /// read-only.
  74.         /// </para>
  75.         /// </devdoc>
  76.         public static readonly DesignOnlyAttribute Default = No;
  77.        
  78.         /// <devdoc>
  79.         /// </devdoc>
  80.         /// <internalonly/>
  81.         public override bool IsDefaultAttribute()
  82.         {
  83.             return IsDesignOnly == Default.IsDesignOnly;
  84.         }
  85.        
  86.         public override bool Equals(object obj)
  87.         {
  88.             if (obj == this) {
  89.                 return true;
  90.             }
  91.            
  92.             DesignOnlyAttribute other = obj as DesignOnlyAttribute;
  93.            
  94.             return (other != null) && other.isDesignOnly == isDesignOnly;
  95.         }
  96.        
  97.         public override int GetHashCode()
  98.         {
  99.             return isDesignOnly.GetHashCode();
  100.         }
  101.     }
  102. }

Developer Fusion