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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="PasswordPropertyTextAttribute.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. namespace System.ComponentModel
  16. {
  17.    
  18.     using System;
  19.     using System.Security.Permissions;
  20.    
  21.     /// <devdoc>
  22.     /// If this attribute is placed on a property or a type, its text representation in a property window
  23.     /// will appear as dots or astrisks to indicate a password field. This indidation in no way
  24.     /// represents any type of encryption or security.
  25.     /// </devdoc>
  26.     [AttributeUsage(AttributeTargets.All)]
  27.     public sealed class PasswordPropertyTextAttribute : Attribute
  28.     {
  29.        
  30.         /// <devdoc>
  31.         /// Sets the System.ComponentModel.Design.PasswordPropertyText
  32.         /// attribute by default to true.
  33.         /// </devdoc>
  34.         public static readonly PasswordPropertyTextAttribute Yes = new PasswordPropertyTextAttribute(true);
  35.        
  36.         /// <devdoc>
  37.         /// Sets the System.ComponentModel.Design.PasswordPropertyText
  38.         /// attribute by default to false.
  39.         /// </devdoc>
  40.         public static readonly PasswordPropertyTextAttribute No = new PasswordPropertyTextAttribute(false);
  41.        
  42.        
  43.         /// <devdoc>
  44.         /// Sets the System.ComponentModel.Design.PasswordPropertyText
  45.         /// attribute by default to false.
  46.         /// </devdoc>
  47.         public static readonly PasswordPropertyTextAttribute Default = No;
  48.        
  49.         private bool _password;
  50.        
  51.         /// <devdoc>
  52.         /// Creates a default PasswordPropertyTextAttribute.
  53.         /// </devdoc>
  54.         public PasswordPropertyTextAttribute() : this(false)
  55.         {
  56.         }
  57.        
  58.         /// <devdoc>
  59.         /// Creates a PasswordPropertyTextAttribute with the given password value.
  60.         /// </devdoc>
  61.         public PasswordPropertyTextAttribute(bool password)
  62.         {
  63.             _password = password;
  64.         }
  65.        
  66.         /// <devdoc>
  67.         /// Gets a value indicating if the property this attribute is defined for should be shown as password text.
  68.         /// </devdoc>
  69.         public bool Password {
  70.             get { return _password; }
  71.         }
  72.        
  73.         /// <devdoc>
  74.         /// Overload for object equality
  75.         /// </devdoc>
  76.         public override bool Equals(object o)
  77.         {
  78.             if (o is PasswordPropertyTextAttribute) {
  79.                 return ((PasswordPropertyTextAttribute)o).Password == _password;
  80.             }
  81.             return false;
  82.         }
  83.        
  84.         /// <devdoc>
  85.         /// Returns the hashcode for this object.
  86.         /// </devdoc>
  87.         public override int GetHashCode()
  88.         {
  89.             return base.GetHashCode();
  90.         }
  91.        
  92.         /// <devdoc>
  93.         /// Gets a value indicating whether this attribute is set to true by default.
  94.         /// </devdoc>
  95.         public override bool IsDefaultAttribute()
  96.         {
  97.             return this.Equals(Default);
  98.         }
  99.     }
  100. }

Developer Fusion