In Test/System.ComponentModel:
[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 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 namespace System.ComponentModel
34 {
35         [AttributeUsage(AttributeTargets.All)]
36         public class PropertyTabAttribute : Attribute
37         {
38
39                 private Type[] tabs;
40                 private PropertyTabScope[] scopes;
41
42
43                 public PropertyTabAttribute()
44                 {
45                         tabs = null;
46                         scopes = null;
47                 }
48
49                 public PropertyTabAttribute (string tabClassName)
50                 {
51                         string[] tabArray = {tabClassName};
52                         this.InitializeArrays (tabArray, null);
53                 }
54
55                 public PropertyTabAttribute (Type tabClass)
56                 {
57                         Type[] tabArray = {tabClass};
58                         this.InitializeArrays (tabArray, null);
59                 }
60
61                 public PropertyTabAttribute (string tabClassName, PropertyTabScope tabScope)
62                 {
63                         string[] tabArray = {tabClassName};
64                         PropertyTabScope[] scopeArray = {tabScope};
65                         this.InitializeArrays (tabArray, scopeArray);
66                 }
67
68                 public PropertyTabAttribute (Type tabClass, PropertyTabScope tabScope)
69                 {
70                         Type[] tabArray = {tabClass};
71                         PropertyTabScope[] scopeArray = {tabScope};
72                         this.InitializeArrays (tabArray, scopeArray);
73                 }
74
75                 public Type[] TabClasses {
76                         get { return tabs; }
77                 }
78
79                 public PropertyTabScope[] TabScopes {
80                         get { return scopes; }
81                 }
82
83                 public override bool Equals (object other)
84                 {
85                         if (!(other is PropertyTabAttribute))
86                                 return false;
87                         if (other == this)
88                                 return true;
89                         return ((PropertyTabAttribute) other).TabClasses == tabs &&
90                                 ((PropertyTabAttribute) other).TabScopes == scopes;
91                 }
92
93                 public bool Equals (PropertyTabAttribute other)
94                 {
95                         return this.Equals ((object) other);
96                 }
97
98                 public override int GetHashCode()
99                 {
100                         // FIXME check if other Hashcode is needed
101                         return base.GetHashCode ();
102                 }
103
104                 protected string[] TabClassNames {
105                         get {
106                                 // FIXME untested, maybe wrong
107                                 string[] tabClassName = (string[]) (Array.CreateInstance (typeof (string), tabs.Length));
108                                 for (int x = 0; x < tabs.Length; x++)
109                                         tabClassName[x] = tabs[x].AssemblyQualifiedName;
110                                 return tabClassName;
111                         }
112                 }
113
114                 protected void InitializeArrays (string[] tabClassNames, PropertyTabScope[] tabScopes)
115                 {
116                         // FIXME untested, maybe wrong
117                         Type[] tabClasses = (Type[]) (Array.CreateInstance (typeof (Type), tabClassNames.Length));
118                         for (int x = 0; x < tabClassNames.Length; x++)
119                                 tabClasses[x] = Type.GetType (tabClassNames[x], false);
120
121                         tabs = tabClasses;
122                         scopes = tabScopes;
123                 }
124
125                 protected void InitializeArrays (Type[] tabClasses, PropertyTabScope[] tabScopes)
126                 {
127                         // FIXME untested, maybe wrong
128                         tabs = tabClasses;
129                         scopes = tabScopes;
130                 }
131         }
132 }