Merge pull request #3040 from xmcclure/debugger-step-recursive
[mono.git] / mcs / class / referencesource / System / compmod / system / componentmodel / design / ToolboxItemAttribute.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="ToolboxItemAttribute.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 // SECREVIEW: remove this attribute once bug#411883 is fixed.
8 [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2113:SecureLateBindingMethods", Scope="member", Target="System.ComponentModel.ToolboxItemAttribute.get_ToolboxItemType():System.Type")]
9
10 namespace System.ComponentModel {
11     
12     using System;
13     using System.Diagnostics;
14     using System.Globalization;
15     using System.Security.Permissions;
16  
17     /// <devdoc>
18     ///    <para>
19     ///       Specifies attributes for a toolbox item.
20     ///    </para>
21     /// </devdoc>
22     [AttributeUsage(AttributeTargets.All)]
23     public class ToolboxItemAttribute : Attribute {
24
25         private Type toolboxItemType;
26         private string toolboxItemTypeName;
27
28         /// <devdoc>
29         ///    <para>
30         ///    Initializes a new instance of ToolboxItemAttribute and sets the type to
31         ///    IComponent.
32         ///    </para>
33         /// </devdoc>
34         public static readonly ToolboxItemAttribute Default = new ToolboxItemAttribute("System.Drawing.Design.ToolboxItem, " + AssemblyRef.SystemDrawing);
35
36         /// <devdoc>
37         ///    <para>
38         ///       Initializes a new instance of ToolboxItemAttribute and sets the type to
39         ///    <see langword='null'/>.
40         ///    </para>
41         /// </devdoc>
42         public static readonly ToolboxItemAttribute None = new ToolboxItemAttribute(false);
43
44         /// <devdoc>
45         ///    <para>
46         ///       Gets whether the attribute is the default attribute.
47         ///    </para>
48         /// </devdoc>
49         public override bool IsDefaultAttribute() {
50             return this.Equals(Default);
51         }
52         
53         /// <devdoc>
54         ///    <para>
55         ///       Initializes a new instance of ToolboxItemAttribute and
56         ///       specifies if default values should be used.
57         ///    </para>
58         /// </devdoc>
59         public ToolboxItemAttribute(bool defaultType) {
60             if (defaultType) {
61                 toolboxItemTypeName = "System.Drawing.Design.ToolboxItem, " + AssemblyRef.SystemDrawing;
62             }
63         }
64
65         /// <devdoc>
66         ///    <para>
67         ///       Initializes a new instance of ToolboxItemAttribute and
68         ///       specifies the name of the type.
69         ///    </para>
70         /// </devdoc>
71         public ToolboxItemAttribute(string toolboxItemTypeName) {
72             string temp = toolboxItemTypeName.ToUpper(CultureInfo.InvariantCulture);
73             Debug.Assert(temp.IndexOf(".DLL") == -1, "Came across: " + toolboxItemTypeName + " . Please remove the .dll extension");
74             this.toolboxItemTypeName = toolboxItemTypeName;
75         }
76
77         /// <devdoc>
78         ///    <para>
79         ///       Initializes a new instance of ToolboxItemAttribute and
80         ///       specifies the type of the toolbox item.
81         ///    </para>
82         /// </devdoc>
83         public ToolboxItemAttribute(Type toolboxItemType) {
84             this.toolboxItemType = toolboxItemType;
85             this.toolboxItemTypeName = toolboxItemType.AssemblyQualifiedName;
86         }
87
88         /// <devdoc>
89         ///    <para>
90         ///       Gets the toolbox item's type.
91         ///    </para>
92         /// </devdoc>
93         public Type ToolboxItemType {
94             get{
95                 if (toolboxItemType == null) {
96                     if (toolboxItemTypeName != null) {
97                         try {
98                             toolboxItemType = Type.GetType(toolboxItemTypeName, true);
99                         }
100                         catch (Exception ex) {
101                             throw new ArgumentException(SR.GetString(SR.ToolboxItemAttributeFailedGetType, toolboxItemTypeName), ex);
102                         }
103                     }
104                 }
105                 return toolboxItemType;
106             }
107         }
108
109         public string ToolboxItemTypeName {
110             get {
111                 if (toolboxItemTypeName == null) {
112                     return String.Empty;
113                 }
114                 return toolboxItemTypeName;
115             }
116         }
117
118         public override bool Equals(object obj) {
119             if (obj == this) {
120                 return true;
121             }
122
123             ToolboxItemAttribute other = obj as ToolboxItemAttribute;
124             return (other != null) && (other.ToolboxItemTypeName == ToolboxItemTypeName);
125         }
126
127         public override int GetHashCode() {
128             if (toolboxItemTypeName != null) {
129                 return toolboxItemTypeName.GetHashCode();
130             }
131             return base.GetHashCode();
132         }
133     }
134 }
135