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

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

Developer Fusion