Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mcs / class / referencesource / System / compmod / system / componentmodel / EditorAttribute.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="EditorAttribute.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 /*
8  */
9 namespace System.ComponentModel {
10     
11     using System.Diagnostics;
12     using System.Globalization;
13
14     /// <devdoc>
15     ///    <para>Specifies the editor to use to change a property. This class cannot be inherited.</para>
16     /// </devdoc>
17     [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
18     public sealed class EditorAttribute : Attribute {
19
20         private string baseTypeName;
21         private string typeName;
22         private string typeId;
23         
24         /// <devdoc>
25         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class with the default editor, which is
26         ///    no editor.</para>
27         /// </devdoc>
28         public EditorAttribute() {
29             this.typeName = string.Empty;
30             this.baseTypeName = string.Empty;
31         }
32
33         /// <devdoc>
34         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class with the type name and base type
35         ///    name of the editor.</para>
36         /// </devdoc>
37         public EditorAttribute(string typeName, string baseTypeName) {
38             string temp = typeName.ToUpperInvariant ();
39             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
40             this.typeName = typeName;
41             this.baseTypeName = baseTypeName;
42         }
43
44         /// <devdoc>
45         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.</para>
46         /// </devdoc>
47         public EditorAttribute(string typeName, Type baseType) {
48             string temp = typeName.ToUpperInvariant ();
49             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + typeName + " . Please remove the .dll extension");
50             this.typeName = typeName;
51             this.baseTypeName = baseType.AssemblyQualifiedName;
52         }
53
54         /// <devdoc>
55         /// <para>Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/>
56         /// class.</para>
57         /// </devdoc>
58         public EditorAttribute(Type type, Type baseType) {
59             this.typeName = type.AssemblyQualifiedName;
60             this.baseTypeName = baseType.AssemblyQualifiedName;
61         }
62
63         /// <devdoc>
64         ///    <para>Gets the name of the base class or interface serving as a lookup key for this editor.</para>
65         /// </devdoc>
66         public string EditorBaseTypeName {
67             get {
68                 return baseTypeName;
69             }
70         }
71
72         /// <devdoc>
73         ///    <para>Gets the name of the editor class.</para>
74         /// </devdoc>
75         public string EditorTypeName {
76             get {
77                 return typeName;
78             }
79         }
80     
81         /// <internalonly/>
82         /// <devdoc>
83         ///    <para>
84         ///       This defines a unique ID for this attribute type. It is used
85         ///       by filtering algorithms to identify two attributes that are
86         ///       the same type. For most attributes, this just returns the
87         ///       Type instance for the attribute. EditorAttribute overrides
88         ///       this to include the type of the editor base type.
89         ///    </para>
90         /// </devdoc>
91         public override object TypeId {
92             get {
93                 if (typeId == null) {
94                     string baseType = baseTypeName;
95                     int comma = baseType.IndexOf(',');
96                     if (comma != -1) {
97                         baseType = baseType.Substring(0, comma);
98                     }
99                     typeId = GetType().FullName + baseType;
100                 }
101                 return typeId;
102             }
103         }
104
105         public override bool Equals(object obj) {
106             if (obj == this) {
107                 return true;
108             }
109
110             EditorAttribute other = obj as EditorAttribute;
111
112             return (other != null) && other.typeName == typeName && other.baseTypeName == baseTypeName;
113         }
114
115         public override int GetHashCode() {
116             return base.GetHashCode();
117         }
118     }
119 }
120