Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System / compmod / system / codedom / CodeTypeDeclaration.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CodeTypeDeclaration.cs" company="Microsoft">
3 // 
4 // <OWNER>[....]</OWNER>
5 //     Copyright (c) Microsoft Corporation.  All rights reserved.
6 // </copyright>                                                                
7 //------------------------------------------------------------------------------
8
9 namespace System.CodeDom {
10
11     using System.Diagnostics;
12     using System;
13     using Microsoft.Win32;
14     using System.Collections;
15     using System.Reflection;
16     using System.Runtime.Serialization;
17     using System.Runtime.InteropServices;
18
19     /// <devdoc>
20     ///    <para>
21     ///       Represents a
22     ///       class or nested class.
23     ///    </para>
24     /// </devdoc>
25     [
26         ClassInterface(ClassInterfaceType.AutoDispatch),
27         ComVisible(true),
28         Serializable,
29     ]
30     public class CodeTypeDeclaration : CodeTypeMember {
31
32
33         private TypeAttributes attributes = Reflection.TypeAttributes.Public | Reflection.TypeAttributes.Class;
34         private CodeTypeReferenceCollection baseTypes = new CodeTypeReferenceCollection();
35         private CodeTypeMemberCollection members = new CodeTypeMemberCollection();
36                 
37         private bool isEnum;    
38         private bool isStruct;
39         private int  populated = 0x0;
40         private const int BaseTypesCollection = 0x1;
41         private const int MembersCollection = 0x2;
42
43         // Need to be made optionally serializable
44         [OptionalField]
45         private CodeTypeParameterCollection typeParameters;
46         [OptionalField]
47         private bool isPartial = false;
48
49
50         /// <devdoc>
51         ///    <para>
52         ///       An event that will be fired the first time the BaseTypes Collection is accessed.  
53         ///    </para>
54         /// </devdoc>
55         public event EventHandler PopulateBaseTypes;
56         
57         /// <devdoc>
58         ///    <para>
59         ///       An event that will be fired the first time the Members Collection is accessed.  
60         ///    </para>
61         /// </devdoc>
62         public event EventHandler PopulateMembers;
63
64
65         /// <devdoc>
66         ///    <para>
67         ///       Initializes a new instance of <see cref='System.CodeDom.CodeTypeDeclaration'/>.
68         ///    </para>
69         /// </devdoc>
70         public CodeTypeDeclaration() {
71         }
72
73         /// <devdoc>
74         ///    <para>
75         ///       Initializes a new instance of <see cref='System.CodeDom.CodeTypeDeclaration'/> with the specified name.
76         ///    </para>
77         /// </devdoc>
78         public CodeTypeDeclaration(string name) {
79             Name = name;
80         }
81
82         /// <devdoc>
83         ///    <para>
84         ///       Gets or sets the attributes of the class.
85         ///    </para>
86         /// </devdoc>
87         public TypeAttributes TypeAttributes {
88             get {
89                 return attributes;
90             }
91             set {
92                 attributes = value;
93             }
94         }
95
96         /// <devdoc>
97         ///    <para>
98         ///       Gets or sets
99         ///       the base types of the class.
100         ///    </para>
101         /// </devdoc>
102         public CodeTypeReferenceCollection BaseTypes {
103             get {
104                 if (0 == (populated & BaseTypesCollection)) {
105                     populated |= BaseTypesCollection;
106                     if (PopulateBaseTypes != null) PopulateBaseTypes(this, EventArgs.Empty);
107                 }
108                 return baseTypes;
109             }
110         }
111
112         /// <devdoc>
113         ///    <para>
114         ///       Gets or sets a value
115         ///       indicating whether the class is a class.
116         ///    </para>
117         /// </devdoc>
118         public bool IsClass {
119             get {
120                 return(attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !isEnum && !isStruct;
121             }
122             set {                  
123                 if (value) {
124                     attributes &= ~TypeAttributes.ClassSemanticsMask;
125                     attributes |= TypeAttributes.Class;
126                     isStruct = false;
127                     isEnum = false;                       
128                 }
129             }
130         }
131
132         /// <devdoc>
133         ///    <para>
134         ///       Gets or sets a value
135         ///       indicating whether the class is a struct.
136         ///    </para>
137         /// </devdoc>
138         public bool IsStruct {
139             get {
140                 return isStruct;
141             }
142             set {        
143                 if (value) {
144                     attributes &= ~TypeAttributes.ClassSemanticsMask;
145                     isStruct = true;
146                     isEnum = false;                       
147                 }                          
148                 else {
149                     isStruct = false;
150                 }
151             }
152         }
153
154         /// <devdoc>
155         ///    <para>
156         ///       Gets or sets a value
157         ///       indicating whether the class is an enumeration.
158         ///    </para>
159         /// </devdoc>
160         public bool IsEnum {
161             get {
162                 return isEnum;
163             }
164             set {
165                 if (value) {
166                     attributes &= ~TypeAttributes.ClassSemanticsMask;
167                     isStruct = false;
168                     isEnum = true;                       
169                 }  
170                 else {
171                     isEnum = false;
172                 }
173             }
174         }
175
176         /// <devdoc>
177         ///    <para>
178         ///       Gets or sets a value
179         ///       indicating whether the class is an interface.
180         ///    </para>
181         /// </devdoc>
182         public bool IsInterface {
183             get {
184                 return(attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
185             }
186             set {
187                 if (value) {
188                     attributes &= ~TypeAttributes.ClassSemanticsMask;
189                     attributes |= TypeAttributes.Interface;
190                     isStruct = false;
191                     isEnum = false;                       
192                 }
193                 else {
194                     attributes &= ~TypeAttributes.Interface;
195                 }
196             }
197         }
198
199         public bool IsPartial {
200             get {
201                 return isPartial;
202             }
203             set {
204                 isPartial = value;
205                 }
206         }
207
208         /// <devdoc>
209         ///    <para>
210         ///       Gets or sets the class member collection members.
211         ///    </para>
212         /// </devdoc>
213         public CodeTypeMemberCollection Members {
214             get {
215                 if (0 == (populated & MembersCollection)) {
216                     populated |= MembersCollection;
217                     if (PopulateMembers != null) PopulateMembers(this, EventArgs.Empty);
218                 }
219                 return members;
220             }
221         }
222
223         [System.Runtime.InteropServices.ComVisible(false)]
224         public CodeTypeParameterCollection TypeParameters {  
225             get {
226                 if( typeParameters == null) {
227                     typeParameters = new CodeTypeParameterCollection();
228                 }
229                 return typeParameters;
230             }
231         }
232     }
233 }