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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ProvidePropertyAttribute.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 which methods are extender
  26.     /// properties.</para>
  27.     /// </devdoc>
  28.     [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  29.     public sealed class ProvidePropertyAttribute : Attribute
  30.     {
  31.         private readonly string propertyName;
  32.         private readonly string receiverTypeName;
  33.        
  34.         /// <devdoc>
  35.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.ProvidePropertyAttribute'/> class.</para>
  36.         /// </devdoc>
  37.         public ProvidePropertyAttribute(string propertyName, Type receiverType)
  38.         {
  39.             this.propertyName = propertyName;
  40.             this.receiverTypeName = receiverType.AssemblyQualifiedName;
  41.         }
  42.        
  43.         /// <devdoc>
  44.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.ProvidePropertyAttribute'/> class.</para>
  45.         /// </devdoc>
  46.         public ProvidePropertyAttribute(string propertyName, string receiverTypeName)
  47.         {
  48.             this.propertyName = propertyName;
  49.             this.receiverTypeName = receiverTypeName;
  50.         }
  51.        
  52.         /// <devdoc>
  53.         /// <para>
  54.         /// Gets the name of a property that this class provides.
  55.         /// </para>
  56.         /// </devdoc>
  57.         public string PropertyName {
  58.             get { return propertyName; }
  59.         }
  60.        
  61.         /// <devdoc>
  62.         /// <para>
  63.         /// Gets the name of the data type this property can extend
  64.         /// </para>
  65.         /// </devdoc>
  66.         public string ReceiverTypeName {
  67.             get { return receiverTypeName; }
  68.         }
  69.        
  70.         /// <devdoc>
  71.         /// <para>ProvidePropertyAttribute overrides this to include the type name and the property name</para>
  72.         /// </devdoc>
  73.         public override object TypeId {
  74.             get { return GetType().FullName + propertyName; }
  75.         }
  76.        
  77.         public override bool Equals(object obj)
  78.         {
  79.             if (obj == this) {
  80.                 return true;
  81.             }
  82.            
  83.             ProvidePropertyAttribute other = obj as ProvidePropertyAttribute;
  84.            
  85.             return (other != null) && other.propertyName == propertyName && other.receiverTypeName == receiverTypeName;
  86.         }
  87.        
  88.         public override int GetHashCode()
  89.         {
  90.             return propertyName.GetHashCode() ^ receiverTypeName.GetHashCode();
  91.         }
  92.     }
  93. }

Developer Fusion