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