2010-03-12 Jb Evain <jbevain@novell.com>
[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 attributes = TypeAttributes.Public;
47                 private bool isEnum;
48                 private bool isStruct;
49                 int populated;
50
51 #if NET_2_0
52                 bool isPartial;
53                 CodeTypeParameterCollection typeParameters;
54 #endif
55
56                 //
57                 // Constructors
58                 //
59
60                 public CodeTypeDeclaration()
61                 {
62                 }
63                 
64                 public CodeTypeDeclaration( string name )
65                 {
66                         this.Name = name;
67                 }
68
69                 /* by default, it's a class */
70
71                 //
72                 // Properties
73                 //
74                 public CodeTypeReferenceCollection BaseTypes {
75                         get {
76                                 if ( baseTypes == null ) {
77                                         baseTypes = new CodeTypeReferenceCollection();
78                                         if ( PopulateBaseTypes != null )
79                                                 PopulateBaseTypes( this, EventArgs.Empty );
80                                 }
81                                 return baseTypes;
82                         }
83                 }
84
85                 public bool IsClass {
86                         get {
87                                 if ( (attributes & TypeAttributes.Interface) != 0 )
88                                         return false;
89                                 if ( isEnum )
90                                         return false;
91                                 if ( isStruct )
92                                         return false;
93                                 return true;
94                         }
95                         set {
96                                 if ( value ) {
97                                         attributes &= ~TypeAttributes.Interface;
98                                         isEnum = false;
99                                         isStruct = false;
100                                 }
101                         }
102                 }
103                 
104                 public bool IsEnum {
105                         get {
106                                 return isEnum;
107                         }
108                         set {
109                                 if ( value ) {
110                                         attributes &= ~TypeAttributes.Interface;
111                                         isEnum = true;
112                                         isStruct = false;
113                                 }
114                         }
115                 }
116
117                 public bool IsInterface {
118                         get {
119                                 return (attributes & TypeAttributes.Interface) != 0;
120                         }
121                         set {
122                                 if ( value ) {
123                                         attributes |= TypeAttributes.Interface;
124                                         isEnum = false;
125                                         isStruct = false;
126                                 }
127                         }
128                 }
129
130                 public bool IsStruct {
131                         get {
132                                 return isStruct;
133                         }
134                         set {
135                                 if ( value ) {
136                                         attributes &= ~TypeAttributes.Interface;
137                                         isEnum = false;
138                                         isStruct = true;
139                                 }
140                         }
141                 }
142
143                 public CodeTypeMemberCollection Members {
144                         get {
145                                 if ( members == null ) {
146                                         members = new CodeTypeMemberCollection();
147                                         if ( PopulateMembers != null )
148                                                 PopulateMembers( this, EventArgs.Empty );
149                                 }
150                                 return members;
151                         }
152                 }
153
154                 public TypeAttributes TypeAttributes {
155                         get {
156                                 return attributes;
157                         }
158                         set {
159                                 attributes = value;
160 #if FALSE
161                                 /* MS does not seem to do this, so don't I */
162                                 if ( (attributes & TypeAttributes.Interface) != 0 ) {
163                                         isEnum = false;
164                                         isStruct = false;
165                                 }
166 #endif
167                         }
168                 }
169
170 #if NET_2_0
171                 public bool IsPartial {
172                         get {
173                                 return isPartial;
174                         }
175                         set {
176                                 isPartial = value;
177                         }
178                 }
179
180                 [ComVisible (false)]
181                 public CodeTypeParameterCollection TypeParameters {
182                         get {
183                                 if (typeParameters == null)
184                                         typeParameters = new CodeTypeParameterCollection ();
185                                 return typeParameters;
186                         }
187                 }
188 #endif
189
190                 //
191                 // Events
192                 // 
193                 public event EventHandler PopulateBaseTypes;
194
195                 public event EventHandler PopulateMembers;
196         }
197 }