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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="BindableAttribute.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.ComponentModel;
  21.     using System.Diagnostics;
  22.     using System.Security.Permissions;
  23.    
  24.     /// <devdoc>
  25.     /// <para>Specifies whether a property is appropriate to bind data
  26.     /// to.</para>
  27.     /// </devdoc>
  28.     [AttributeUsage(AttributeTargets.All)]
  29.     public sealed class BindableAttribute : Attribute
  30.     {
  31.         /// <devdoc>
  32.         /// <para>
  33.         /// Specifies that a property is appropriate to bind data to. This
  34.         /// <see langword='static '/>field is read-only.
  35.         /// </para>
  36.         /// </devdoc>
  37.         public static readonly BindableAttribute Yes = new BindableAttribute(true);
  38.        
  39.         /// <devdoc>
  40.         /// <para>
  41.         /// Specifies that a property is not appropriate to bind
  42.         /// data to. This <see langword='static '/>field is read-only.
  43.         /// </para>
  44.         /// </devdoc>
  45.         public static readonly BindableAttribute No = new BindableAttribute(false);
  46.        
  47.         /// <devdoc>
  48.         /// <para>
  49.         /// Specifies the default value for the <see cref='System.ComponentModel.BindableAttribute'/>,
  50.         /// which is <see cref='System.ComponentModel.BindableAttribute.No'/>. This <see langword='static '/>field is
  51.         /// read-only.
  52.         /// </para>
  53.         /// </devdoc>
  54.         public static readonly BindableAttribute Default = No;
  55.        
  56.         private bool bindable = false;
  57.         private bool isDefault = false;
  58.         private BindingDirection direction;
  59.        
  60.         /// <devdoc>
  61.         /// <para>
  62.         /// Initializes a new instance of the <see cref='System.ComponentModel.BindableAttribute'/> class.
  63.         /// </para>
  64.         /// </devdoc>
  65.         public BindableAttribute(bool bindable) : this(bindable, BindingDirection.OneWay)
  66.         {
  67.         }
  68.        
  69.         /// <devdoc>
  70.         /// <para>
  71.         /// Initializes a new instance of the <see cref='System.ComponentModel.BindableAttribute'/> class.
  72.         /// </para>
  73.         /// </devdoc>
  74.         public BindableAttribute(bool bindable, BindingDirection direction)
  75.         {
  76.             this.bindable = bindable;
  77.             this.direction = direction;
  78.         }
  79.        
  80.         /// <devdoc>
  81.         /// <para>
  82.         /// Initializes a new instance of the <see cref='System.ComponentModel.BindableAttribute'/> class.
  83.         /// </para>
  84.         /// </devdoc>
  85.         public BindableAttribute(BindableSupport flags) : this(flags, BindingDirection.OneWay)
  86.         {
  87.         }
  88.        
  89.         /// <devdoc>
  90.         /// <para>
  91.         /// Initializes a new instance of the <see cref='System.ComponentModel.BindableAttribute'/> class.
  92.         /// </para>
  93.         /// </devdoc>
  94.         public BindableAttribute(BindableSupport flags, BindingDirection direction)
  95.         {
  96.             this.bindable = (flags != BindableSupport.No);
  97.             this.isDefault = (flags == BindableSupport.Default);
  98.             this.direction = direction;
  99.         }
  100.        
  101.         /// <devdoc>
  102.         /// <para>
  103.         /// Gets a value indicating
  104.         /// whether a property is appropriate to bind data to.
  105.         /// </para>
  106.         /// </devdoc>
  107.         public bool Bindable {
  108.             get { return bindable; }
  109.         }
  110.        
  111.         /// <devdoc>
  112.         /// <para>
  113.         /// Gets a value indicating
  114.         /// the direction(s) this property be bound to data.
  115.         /// </para>
  116.         /// </devdoc>
  117.         public BindingDirection Direction {
  118.             get { return direction; }
  119.         }
  120.        
  121.         /// <internalonly/>
  122.         /// <devdoc>
  123.         /// </devdoc>
  124.         public override bool Equals(object obj)
  125.         {
  126.             if (obj == this) {
  127.                 return true;
  128.             }
  129.            
  130.             if (obj != null && obj is BindableAttribute) {
  131.                 return (((BindableAttribute)obj).Bindable == bindable);
  132.             }
  133.            
  134.             return false;
  135.         }
  136.        
  137.         /// <devdoc>
  138.         /// <para>[To be supplied.]</para>
  139.         /// </devdoc>
  140.         public override int GetHashCode()
  141.         {
  142.             return bindable.GetHashCode();
  143.         }
  144.        
  145.         /// <devdoc>
  146.         /// </devdoc>
  147.         /// <internalonly/>
  148.         public override bool IsDefaultAttribute()
  149.         {
  150.             return (this.Equals(Default) || isDefault);
  151.         }
  152.     }
  153. }

Developer Fusion