1 //------------------------------------------------------------------------------
2 // <copyright file="ToolboxItemAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
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")]
10 namespace System.ComponentModel {
13 using System.Diagnostics;
14 using System.Globalization;
15 using System.Security.Permissions;
19 /// Specifies attributes for a toolbox item.
22 [AttributeUsage(AttributeTargets.All)]
23 public class ToolboxItemAttribute : Attribute {
25 private Type toolboxItemType;
26 private string toolboxItemTypeName;
30 /// Initializes a new instance of ToolboxItemAttribute and sets the type to
34 public static readonly ToolboxItemAttribute Default = new ToolboxItemAttribute("System.Drawing.Design.ToolboxItem, " + AssemblyRef.SystemDrawing);
38 /// Initializes a new instance of ToolboxItemAttribute and sets the type to
39 /// <see langword='null'/>.
42 public static readonly ToolboxItemAttribute None = new ToolboxItemAttribute(false);
46 /// Gets whether the attribute is the default attribute.
49 public override bool IsDefaultAttribute() {
50 return this.Equals(Default);
55 /// Initializes a new instance of ToolboxItemAttribute and
56 /// specifies if default values should be used.
59 public ToolboxItemAttribute(bool defaultType) {
61 toolboxItemTypeName = "System.Drawing.Design.ToolboxItem, " + AssemblyRef.SystemDrawing;
67 /// Initializes a new instance of ToolboxItemAttribute and
68 /// specifies the name of the type.
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;
79 /// Initializes a new instance of ToolboxItemAttribute and
80 /// specifies the type of the toolbox item.
83 public ToolboxItemAttribute(Type toolboxItemType) {
84 this.toolboxItemType = toolboxItemType;
85 this.toolboxItemTypeName = toolboxItemType.AssemblyQualifiedName;
90 /// Gets the toolbox item's type.
93 public Type ToolboxItemType {
95 if (toolboxItemType == null) {
96 if (toolboxItemTypeName != null) {
98 toolboxItemType = Type.GetType(toolboxItemTypeName, true);
100 catch (Exception ex) {
101 throw new ArgumentException(SR.GetString(SR.ToolboxItemAttributeFailedGetType, toolboxItemTypeName), ex);
105 return toolboxItemType;
109 public string ToolboxItemTypeName {
111 if (toolboxItemTypeName == null) {
114 return toolboxItemTypeName;
118 public override bool Equals(object obj) {
123 ToolboxItemAttribute other = obj as ToolboxItemAttribute;
124 return (other != null) && (other.ToolboxItemTypeName == ToolboxItemTypeName);
127 public override int GetHashCode() {
128 if (toolboxItemTypeName != null) {
129 return toolboxItemTypeName.GetHashCode();
131 return base.GetHashCode();