ToolboxItemAttribute.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // System.ComponentModel.ToolboxItemAttribute
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. namespace System.ComponentModel
  11. {
  12. [AttributeUsage(AttributeTargets.All)]
  13. public class ToolboxItemAttribute : Attribute
  14. {
  15. private static string defaultItemType = "System.Drawing.Design.ToolboxItem,System.Drawing";
  16. public static readonly ToolboxItemAttribute Default = new ToolboxItemAttribute (defaultItemType);
  17. public static readonly ToolboxItemAttribute None = new ToolboxItemAttribute (false);
  18. private Type itemType;
  19. private string itemTypeName;
  20. public ToolboxItemAttribute (bool defaultType)
  21. {
  22. if (defaultType)
  23. itemTypeName = defaultItemType;
  24. }
  25. public ToolboxItemAttribute (string toolboxItemName)
  26. {
  27. itemTypeName = toolboxItemName;
  28. }
  29. public ToolboxItemAttribute (Type toolboxItemType)
  30. {
  31. itemType = toolboxItemType;
  32. }
  33. public Type ToolboxItemType
  34. {
  35. get {
  36. if (itemType == null && itemTypeName != null)
  37. itemType = Type.GetType (itemTypeName);
  38. return itemType;
  39. }
  40. }
  41. public string ToolboxItemTypeName
  42. {
  43. get {
  44. if (itemTypeName == null) {
  45. if (itemType == null)
  46. return "";
  47. itemTypeName = itemType.AssemblyQualifiedName;
  48. }
  49. return itemTypeName;
  50. }
  51. }
  52. public override bool Equals (object o)
  53. {
  54. if (!(o is ToolboxItemAttribute))
  55. return false;
  56. return (((ToolboxItemAttribute) o).ToolboxItemTypeName == ToolboxItemTypeName);
  57. }
  58. public override int GetHashCode ()
  59. {
  60. return base.GetHashCode ();
  61. }
  62. public override bool IsDefaultAttribute ()
  63. {
  64. return Equals (Default);
  65. }
  66. }
  67. }