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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="TypeConverterAttribute.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.Diagnostics;
  20.     using System.Globalization;
  21.     using System.Runtime.Serialization.Formatters;
  22.     using System.Security.Permissions;
  23.    
  24.     /// <devdoc>
  25.     /// <para>Specifies what type to use as
  26.     /// a converter for the object
  27.     /// this
  28.     /// attribute is bound to. This class cannot
  29.     /// be inherited.</para>
  30.     /// </devdoc>
  31.     [AttributeUsage(AttributeTargets.All)]
  32.     public sealed class TypeConverterAttribute : Attribute
  33.     {
  34.         private string typeName;
  35.        
  36.         /// <devdoc>
  37.         /// <para> Specifies the type to use as
  38.         /// a converter for the object this attribute is bound to. This
  39.         /// <see langword='static '/>field is read-only. </para>
  40.         /// </devdoc>
  41.         public static readonly TypeConverterAttribute Default = new TypeConverterAttribute();
  42.        
  43.         /// <devdoc>
  44.         /// <para>
  45.         /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class with the
  46.         /// default type converter, which
  47.         /// is an
  48.         /// empty string ("").
  49.         /// </para>
  50.         /// </devdoc>
  51.         public TypeConverterAttribute()
  52.         {
  53.             this.typeName = string.Empty;
  54.         }
  55.        
  56.         /// <devdoc>
  57.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class, using
  58.         /// the specified type as the data converter for the object this attribute
  59.         /// is bound
  60.         /// to.</para>
  61.         /// </devdoc>
  62.         public TypeConverterAttribute(Type type)
  63.         {
  64.             this.typeName = type.AssemblyQualifiedName;
  65.         }
  66.        
  67.         /// <devdoc>
  68.         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class, using
  69.         /// the specified type name as the data converter for the object this attribute is bound to.</para>
  70.         /// </devdoc>
  71.         public TypeConverterAttribute(string typeName)
  72.         {
  73.             string temp = typeName.ToUpper(CultureInfo.InvariantCulture);
  74.             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
  75.             this.typeName = typeName;
  76.         }
  77.        
  78.         /// <devdoc>
  79.         /// <para>Gets the fully qualified type name of the <see cref='System.Type'/>
  80.         /// to use as a converter for the object this attribute
  81.         /// is bound to.</para>
  82.         /// </devdoc>
  83.         public string ConverterTypeName {
  84.             get { return typeName; }
  85.         }
  86.        
  87.         public override bool Equals(object obj)
  88.         {
  89.             TypeConverterAttribute other = obj as TypeConverterAttribute;
  90.             return (other != null) && other.ConverterTypeName == typeName;
  91.         }
  92.        
  93.         public override int GetHashCode()
  94.         {
  95.             return typeName.GetHashCode();
  96.         }
  97.     }
  98. }

Developer Fusion