PropertyTabAttribute.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // System.ComponentModel.PropertyTabAttribute
  3. //
  4. // Authors:
  5. // Martin Willemoes Hansen ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) 2003 Martin Willemoes Hansen
  9. // (C) 2003 Andreas Nahr
  10. //
  11. namespace System.ComponentModel
  12. {
  13. [AttributeUsage(AttributeTargets.All)]
  14. public class PropertyTabAttribute : Attribute
  15. {
  16. private Type[] tabs;
  17. private PropertyTabScope[] scopes;
  18. public PropertyTabAttribute()
  19. {
  20. tabs = null;
  21. scopes = null;
  22. }
  23. public PropertyTabAttribute (string tabClassName)
  24. {
  25. string[] tabArray = {tabClassName};
  26. this.InitializeArrays (tabArray, null);
  27. }
  28. public PropertyTabAttribute (Type tabClass)
  29. {
  30. Type[] tabArray = {tabClass};
  31. this.InitializeArrays (tabArray, null);
  32. }
  33. public PropertyTabAttribute (string tabClassName, PropertyTabScope tabScope)
  34. {
  35. string[] tabArray = {tabClassName};
  36. PropertyTabScope[] scopeArray = {tabScope};
  37. this.InitializeArrays (tabArray, scopeArray);
  38. }
  39. public PropertyTabAttribute (Type tabClass, PropertyTabScope tabScope)
  40. {
  41. Type[] tabArray = {tabClass};
  42. PropertyTabScope[] scopeArray = {tabScope};
  43. this.InitializeArrays (tabArray, scopeArray);
  44. }
  45. public Type[] TabClasses {
  46. get { return tabs; }
  47. }
  48. public PropertyTabScope[] TabScopes {
  49. get { return scopes; }
  50. }
  51. public override bool Equals (object other)
  52. {
  53. if (!(other is PropertyTabAttribute))
  54. return false;
  55. if (other == this)
  56. return true;
  57. return ((PropertyTabAttribute) other).TabClasses == tabs &&
  58. ((PropertyTabAttribute) other).TabScopes == scopes;
  59. }
  60. public bool Equals (PropertyTabAttribute other)
  61. {
  62. return this.Equals (other);
  63. }
  64. public override int GetHashCode()
  65. {
  66. // FIXME check if other Hashcode is needed
  67. return base.GetHashCode ();
  68. }
  69. protected string[] TabClassNames {
  70. get {
  71. // FIXME untested, maybe wrong
  72. string[] tabClassName = (string[]) (Array.CreateInstance (typeof (string), tabs.Length));
  73. for (int x = 0; x < tabs.Length; x++)
  74. tabClassName[x] = tabs[x].AssemblyQualifiedName;
  75. return tabClassName;
  76. }
  77. }
  78. protected void InitializeArrays (string[] tabClassNames, PropertyTabScope[] tabScopes)
  79. {
  80. // FIXME untested, maybe wrong
  81. Type[] tabClasses = (Type[]) (Array.CreateInstance (typeof (Type), tabClassNames.Length));
  82. for (int x = 0; x < tabClassNames.Length; x++)
  83. tabClasses[x] = Type.GetType (tabClassNames[x], false);
  84. tabs = tabClasses;
  85. scopes = tabScopes;
  86. }
  87. protected void InitializeArrays (Type[] tabClasses, PropertyTabScope[] tabScopes)
  88. {
  89. // FIXME untested, maybe wrong
  90. tabs = tabClasses;
  91. scopes = tabScopes;
  92. }
  93. }
  94. }