New test.
[mono.git] / mcs / class / System / System.CodeDom / CodeTypeDeclaration.cs
1 //
2 // System.CodeDom CodeTypeDeclaration Class implementation
3 //
4 // Author:
5 //   Sean MacIsaac (macisaac@ximian.com)
6 //   Daniel Stodden (stodden@in.tum.de)
7 //   Marek Safar (marek.safar@seznam.cz)
8 //
9 // (C) 2001 Ximian, Inc.
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 using System.Runtime.InteropServices;
34 using System.Reflection;
35
36 namespace System.CodeDom
37 {
38         [Serializable]
39         [ClassInterface(ClassInterfaceType.AutoDispatch)]
40         [ComVisible(true)]
41         public class CodeTypeDeclaration
42                 : CodeTypeMember
43         {
44                 private CodeTypeReferenceCollection baseTypes;
45                 private CodeTypeMemberCollection members;
46                 private TypeAttributes typeAttributes = TypeAttributes.Public;
47                 private bool isEnum;
48                 private bool isStruct;
49
50 #if NET_2_0
51                 bool isPartial;
52                 CodeTypeParameterCollection typeParameters;
53 #endif
54
55                 //
56                 // Constructors
57                 //
58
59                 public CodeTypeDeclaration()
60                 {
61                 }
62                 
63                 public CodeTypeDeclaration( string name )
64                 {
65                         this.Name = name;
66                 }
67
68                 /* by default, it's a class */
69
70                 //
71                 // Properties
72                 //
73                 public CodeTypeReferenceCollection BaseTypes {
74                         get {
75                                 if ( baseTypes == null ) {
76                                         baseTypes = new CodeTypeReferenceCollection();
77                                         if ( PopulateBaseTypes != null )
78                                                 PopulateBaseTypes( this, EventArgs.Empty );
79                                 }
80                                 return baseTypes;
81                         }
82                 }
83
84                 public bool IsClass {
85                         get {
86                                 if ( (typeAttributes & TypeAttributes.Interface) != 0 )
87                                         return false;
88                                 if ( isEnum )
89                                         return false;
90                                 if ( isStruct )
91                                         return false;
92                                 return true;
93                         }
94                         set {
95                                 if ( value ) {
96                                         typeAttributes &= ~TypeAttributes.Interface;
97                                         isEnum = false;
98                                         isStruct = false;
99                                 }
100                         }
101                 }
102                 
103                 public bool IsEnum {
104                         get {
105                                 return isEnum;
106                         }
107                         set {
108                                 if ( value ) {
109                                         typeAttributes &= ~TypeAttributes.Interface;
110                                         isEnum = true;
111                                         isStruct = false;
112                                 }
113                         }
114                 }
115
116                 public bool IsInterface {
117                         get {
118                                 return (typeAttributes & TypeAttributes.Interface) != 0;
119                         }
120                         set {
121                                 if ( value ) {
122                                         typeAttributes |= TypeAttributes.Interface;
123                                         isEnum = false;
124                                         isStruct = false;
125                                 }
126                         }
127                 }
128
129                 public bool IsStruct {
130                         get {
131                                 return isStruct;
132                         }
133                         set {
134                                 if ( value ) {
135                                         typeAttributes &= ~TypeAttributes.Interface;
136                                         isEnum = false;
137                                         isStruct = true;
138                                 }
139                         }
140                 }
141
142                 public CodeTypeMemberCollection Members {
143                         get {
144                                 if ( members == null ) {
145                                         members = new CodeTypeMemberCollection();
146                                         if ( PopulateMembers != null )
147                                                 PopulateMembers( this, EventArgs.Empty );
148                                 }
149                                 return members;
150                         }
151                 }
152
153                 public TypeAttributes TypeAttributes {
154                         get {
155                                 return typeAttributes;
156                         }
157                         set {
158                                 typeAttributes = value;
159 #if FALSE
160                                 /* MS does not seem to do this, so don't I */
161                                 if ( (typeAttributes & TypeAttributes.Interface) != 0 ) {
162                                         isEnum = false;
163                                         isStruct = false;
164                                 }
165 #endif
166                         }
167                 }
168
169 #if NET_2_0
170                 public bool IsPartial {
171                         get {
172                                 return isPartial;
173                         }
174                         set {
175                                 isPartial = value;
176                         }
177                 }
178
179                 [ComVisible (false)]
180                 public CodeTypeParameterCollection TypeParameters {
181                         get {
182                                 if (typeParameters == null)
183                                         typeParameters = new CodeTypeParameterCollection ();
184                                 return typeParameters;
185                         }
186                 }
187 #endif
188
189                 //
190                 // Events
191                 // 
192                 public event EventHandler PopulateBaseTypes;
193
194                 public event EventHandler PopulateMembers;
195         }
196 }