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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="NotifyParentPropertyAttribute.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.Security.Permissions;
  22.    
  23.     /// <devdoc>
  24.     /// <para>
  25.     /// Indicates whether the parent property is notified
  26.     /// if a child namespace property is modified.
  27.     /// </para>
  28.     /// </devdoc>
  29.     [AttributeUsage(AttributeTargets.Property)]
  30.     public sealed class NotifyParentPropertyAttribute : Attribute
  31.     {
  32.        
  33.         /// <devdoc>
  34.         /// <para>
  35.         /// Specifies that the parent property should be notified on changes to the child class property. This field is read-only.
  36.         /// </para>
  37.         /// </devdoc>
  38.         public static readonly NotifyParentPropertyAttribute Yes = new NotifyParentPropertyAttribute(true);
  39.        
  40.         /// <devdoc>
  41.         /// <para>Specifies that the parent property should not be notified of changes to the child class property. This field is read-only.</para>
  42.         /// </devdoc>
  43.         public static readonly NotifyParentPropertyAttribute No = new NotifyParentPropertyAttribute(false);
  44.        
  45.         /// <devdoc>
  46.         /// <para>Specifies the default attribute state, that the parent property should not be notified of changes to the child class property.
  47.         /// This field is read-only.</para>
  48.         /// </devdoc>
  49.         public static readonly NotifyParentPropertyAttribute Default = No;
  50.        
  51.         private bool notifyParent = false;
  52.        
  53.        
  54.         /// <devdoc>
  55.         /// <para>Initiailzes a new instance of the NotifyPropertyAttribute class
  56.         /// that uses the specified value
  57.         /// to indicate whether the parent property should be notified when a child namespace property is modified.</para>
  58.         /// </devdoc>
  59.         public NotifyParentPropertyAttribute(bool notifyParent)
  60.         {
  61.             this.notifyParent = notifyParent;
  62.         }
  63.        
  64.        
  65.         /// <devdoc>
  66.         /// <para>
  67.         /// Gets or sets whether the parent property should be notified
  68.         /// on changes to a child namespace property.
  69.         /// </para>
  70.         /// </devdoc>
  71.         public bool NotifyParent {
  72.             get { return notifyParent; }
  73.         }
  74.        
  75.        
  76.         /// <devdoc>
  77.         /// <para>
  78.         /// Tests whether the specified object is the same as the current object.
  79.         /// </para>
  80.         /// </devdoc>
  81.         public override bool Equals(object obj)
  82.         {
  83.             if (obj == this) {
  84.                 return true;
  85.             }
  86.             if ((obj != null) && (obj is NotifyParentPropertyAttribute)) {
  87.                 return ((NotifyParentPropertyAttribute)obj).NotifyParent == notifyParent;
  88.             }
  89.            
  90.             return false;
  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.         /// <devdoc>
  104.         /// <para>
  105.         /// Gets whether this attribute is <see langword='true'/> by default.
  106.         /// </para>
  107.         /// </devdoc>
  108.         public override bool IsDefaultAttribute()
  109.         {
  110.             return this.Equals(Default);
  111.         }
  112.     }
  113. }

Developer Fusion