1 //------------------------------------------------------------------------------
2 // <copyright file="CodeTypeDeclaration.cs" company="Microsoft">
4 // <OWNER>[....]</OWNER>
5 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //------------------------------------------------------------------------------
9 namespace System.CodeDom {
11 using System.Diagnostics;
13 using Microsoft.Win32;
14 using System.Collections;
15 using System.Reflection;
16 using System.Runtime.Serialization;
17 using System.Runtime.InteropServices;
22 /// class or nested class.
26 ClassInterface(ClassInterfaceType.AutoDispatch),
30 public class CodeTypeDeclaration : CodeTypeMember {
33 private TypeAttributes attributes = Reflection.TypeAttributes.Public | Reflection.TypeAttributes.Class;
34 private CodeTypeReferenceCollection baseTypes = new CodeTypeReferenceCollection();
35 private CodeTypeMemberCollection members = new CodeTypeMemberCollection();
38 private bool isStruct;
39 private int populated = 0x0;
40 private const int BaseTypesCollection = 0x1;
41 private const int MembersCollection = 0x2;
43 // Need to be made optionally serializable
45 private CodeTypeParameterCollection typeParameters;
47 private bool isPartial = false;
52 /// An event that will be fired the first time the BaseTypes Collection is accessed.
55 public event EventHandler PopulateBaseTypes;
59 /// An event that will be fired the first time the Members Collection is accessed.
62 public event EventHandler PopulateMembers;
67 /// Initializes a new instance of <see cref='System.CodeDom.CodeTypeDeclaration'/>.
70 public CodeTypeDeclaration() {
75 /// Initializes a new instance of <see cref='System.CodeDom.CodeTypeDeclaration'/> with the specified name.
78 public CodeTypeDeclaration(string name) {
84 /// Gets or sets the attributes of the class.
87 public TypeAttributes TypeAttributes {
99 /// the base types of the class.
102 public CodeTypeReferenceCollection BaseTypes {
104 if (0 == (populated & BaseTypesCollection)) {
105 populated |= BaseTypesCollection;
106 if (PopulateBaseTypes != null) PopulateBaseTypes(this, EventArgs.Empty);
114 /// Gets or sets a value
115 /// indicating whether the class is a class.
118 public bool IsClass {
120 return(attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !isEnum && !isStruct;
124 attributes &= ~TypeAttributes.ClassSemanticsMask;
125 attributes |= TypeAttributes.Class;
134 /// Gets or sets a value
135 /// indicating whether the class is a struct.
138 public bool IsStruct {
144 attributes &= ~TypeAttributes.ClassSemanticsMask;
156 /// Gets or sets a value
157 /// indicating whether the class is an enumeration.
166 attributes &= ~TypeAttributes.ClassSemanticsMask;
178 /// Gets or sets a value
179 /// indicating whether the class is an interface.
182 public bool IsInterface {
184 return(attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
188 attributes &= ~TypeAttributes.ClassSemanticsMask;
189 attributes |= TypeAttributes.Interface;
194 attributes &= ~TypeAttributes.Interface;
199 public bool IsPartial {
210 /// Gets or sets the class member collection members.
213 public CodeTypeMemberCollection Members {
215 if (0 == (populated & MembersCollection)) {
216 populated |= MembersCollection;
217 if (PopulateMembers != null) PopulateMembers(this, EventArgs.Empty);
223 [System.Runtime.InteropServices.ComVisible(false)]
224 public CodeTypeParameterCollection TypeParameters {
226 if( typeParameters == null) {
227 typeParameters = new CodeTypeParameterCollection();
229 return typeParameters;