Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CodeTypeDeclaration.cs « System.CodeDom « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be0fdc70cff399b8284241263848c05e88f43515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// System.CodeDom CodeTypeDeclaration Class implementation
//
// Author:
//   Sean MacIsaac (macisaac@ximian.com)
//   Daniel Stodden (stodden@in.tum.de)
//
// (C) 2001 Ximian, Inc.
//

using System.Runtime.InteropServices;
using System.Reflection;

namespace System.CodeDom
{
	[Serializable]
	[ClassInterface(ClassInterfaceType.AutoDispatch)]
	[ComVisible(true)]
	public class CodeTypeDeclaration
		: CodeTypeMember
	{
		private CodeTypeReferenceCollection baseTypes;
		private CodeTypeMemberCollection members;
		private TypeAttributes typeAttributes;
		private bool isEnum;
		private bool isStruct;

		//
		// Constructors
		//

		public CodeTypeDeclaration()
		{
		}
		
		public CodeTypeDeclaration( string name )
		{
			this.Name = name;
		}

		/* by default, it's a class */

		//
		// Properties
		//
		public CodeTypeReferenceCollection BaseTypes {
			get {
				if ( baseTypes == null ) {
					baseTypes = new CodeTypeReferenceCollection();
					if ( PopulateBaseTypes != null )
						PopulateBaseTypes( this, EventArgs.Empty );
				}
				return baseTypes;
			}
		}

		public bool IsClass {
			get {
				if ( (typeAttributes & TypeAttributes.Interface) != 0 )
					return false;
				if ( isEnum )
					return false;
				if ( isStruct )
					return false;
				return true;
			}
			set {
				if ( value ) {
					typeAttributes &= ~TypeAttributes.Interface;
					isEnum = false;
					isStruct = false;
				}
			}
		}
		
		public bool IsEnum {
			get {
				return isEnum;
			}
			set {
				if ( value ) {
					typeAttributes &= ~TypeAttributes.Interface;
					isEnum = true;
					isStruct = false;
				}
			}
		}

		public bool IsInterface {
			get {
				return (typeAttributes & TypeAttributes.Interface) != 0;
			}
			set {
				if ( value ) {
					typeAttributes |= TypeAttributes.Interface;
					isEnum = false;
					isStruct = false;
				}
			}
		}

		public bool IsStruct {
			get {
				return isStruct;
			}
			set {
				if ( value ) {
					typeAttributes &= ~TypeAttributes.Interface;
					isEnum = false;
					isStruct = true;
				}
			}
		}

		public CodeTypeMemberCollection Members {
			get {
				if ( members == null ) {
					members = new CodeTypeMemberCollection();
					if ( PopulateMembers != null )
						PopulateMembers( this, EventArgs.Empty );
				}
				return members;
			}
		}

		public TypeAttributes TypeAttributes {
			get {
				return typeAttributes;
			}
			set {
				typeAttributes = value;
#if FALSE
				/* MS does not seem to do this, so don't I */
				if ( (typeAttributes & TypeAttributes.Interface) != 0 ) {
					isEnum = false;
					isStruct = false;
				}
#endif
			}
		}

		//
		// Events
		// 
		public event EventHandler PopulateBaseTypes;

		public event EventHandler PopulateMembers;
	}
}