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

MonoType.cs « System « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7cc909bc4c9806f48257260b880d2e67c1e84249 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//
// System.MonoType
//
// Sean MacIsaac (macisaac@ximian.com)
// Paolo Molaro (lupus@ximian.com)
// Patrik Torstensson (patrik.torstensson@labs2.com)
//
// (C) 2001 Ximian, Inc.
//

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Globalization;

namespace System
{
	internal struct MonoTypeInfo {
		public string name;
		public string name_space;
		public Type parent;
		public Type etype;
		public Assembly assembly;
		public TypeAttributes attrs;
		public int rank;
		public bool isbyref;
		public bool ispointer;
		public bool isprimitive;
	}

	internal class MonoType : Type
	{

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private static extern void type_from_obj (MonoType type, Object obj);
		
		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private static extern void get_type_info (RuntimeTypeHandle type, out MonoTypeInfo info);

		[MonoTODO]
		internal MonoType (Object obj)
		{
			// this should not be used - lupus
			type_from_obj (this, obj);
			
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private static extern TypeAttributes get_attributes (Type type);
	
		protected override TypeAttributes GetAttributeFlagsImpl ()
		{
			return get_attributes (this);
		}

		[MonoTODO]
		protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
								       Binder binder,
								       CallingConventions callConvention,
								       Type[] types,
								       ParameterModifier[] modifiers)
		{
			// FIXME
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr);

		[MonoTODO]
		public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
		{
			// FIXME
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override EventInfo[] GetEvents (BindingFlags bindingAttr);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override FieldInfo GetField (string name, BindingFlags bindingAttr);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override FieldInfo[] GetFields (BindingFlags bindingAttr);

		public override Type GetInterface (string name, bool ignoreCase)
		{
			if (name == null)
				throw new ArgumentNullException ();

			Type[] interfaces = GetInterfaces();

			foreach (Type type in interfaces)
				if (String.Compare (type.Name, name, ignoreCase) == 0)
					return type;

			return null;
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		[MonoTODO]
		public extern override Type[] GetInterfaces();
		
		public override MemberInfo[] GetMembers( BindingFlags bindingAttr)
		{
			// FIXME
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override MethodInfo[] GetMethods (BindingFlags bindingAttr);

		protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
							     Binder binder,
							     CallingConventions callConvention,
							     Type[] types, ParameterModifier[] modifiers)
		{
			// FIXME
			throw new NotImplementedException ();
		}
		
		public override Type GetNestedType( string name, BindingFlags bindingAttr)
		{
			// FIXME
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override Type[] GetNestedTypes (BindingFlags bindingAttr);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override PropertyInfo[] GetProperties( BindingFlags bindingAttr);

		[MonoTODO]
		protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
								 Binder binder, Type returnType,
								 Type[] types,
								 ParameterModifier[] modifiers)
		{
			// fixme: needs to use the binder, and send the modifiers to that binder
			if (null == name || types == null)
				throw new ArgumentNullException ();
			
			PropertyInfo ret = null;
			PropertyInfo [] props = GetProperties(bindingAttr);

			foreach (PropertyInfo info in props) {
					if (info.Name != name) 
						continue;

					if (returnType != null)
						if (info.GetGetMethod().ReturnType != returnType)
							continue;

					if (types.Length > 0) {
						if (info.GetIndexParameters().Length != types.Length)
							continue;
	
						// fixme: compare parameters
					}

					if (null != ret)
						throw new AmbiguousMatchException();

					ret = info;
			}

			return ret;
		}

		protected override bool HasElementTypeImpl ()
		{
			return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
		}

		protected override bool IsArrayImpl ()
		{
			return type_is_subtype_of (this, typeof (System.Array), false);
		}

		protected override bool IsByRefImpl ()
		{
			MonoTypeInfo info;

			get_type_info (_impl, out info);
			return info.isbyref;
		}

		protected override bool IsCOMObjectImpl ()
		{
			return false;
		}

		protected override bool IsPointerImpl ()
		{
			MonoTypeInfo info;

			get_type_info (_impl, out info);
			return info.ispointer;
		}

		protected override bool IsPrimitiveImpl ()
		{
			MonoTypeInfo info;

			get_type_info (_impl, out info);
			return info.isprimitive;
		}

		protected override bool IsValueTypeImpl ()
		{
			return type_is_subtype_of (this, typeof (System.ValueType), false) &&
				this != typeof (System.ValueType) &&
				this != typeof (System.Enum);
		}
		
		public override object InvokeMember (string name, BindingFlags invokeAttr,
						     Binder binder, object target, object[] args,
						     ParameterModifier[] modifiers,
						     CultureInfo culture, string[] namedParameters)
		{
			// FIXME
			throw new NotImplementedException ();
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		public extern override Type GetElementType ();

		public override Type UnderlyingSystemType {
			get {
				MonoTypeInfo info;
				get_type_info (_impl, out info);
				return info.etype;
			}
		}

		public override Assembly Assembly {
			get {
				MonoTypeInfo info;
				get_type_info (_impl, out info);
				return info.assembly;
			}
		}

		public override string AssemblyQualifiedName {
			get {
				return getFullName () + "," + Assembly.ToString ();
			}
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private extern string getFullName();

		public override Type BaseType {
			get {
				MonoTypeInfo info;
				get_type_info (_impl, out info);
				return info.parent;
			}
		}

		public override string FullName {
			get {
				return getFullName ();
			}
		}

		public override Guid GUID {
			get {
				return Guid.Empty;
			}
		}

		public override bool IsDefined (Type attributeType, bool inherit)
		{
			return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
		}

		public override object[] GetCustomAttributes (bool inherit)
		{
			return MonoCustomAttrs.GetCustomAttributes (this, inherit);
		}

		public override object[] GetCustomAttributes (Type attributeType, bool inherit)
		{
			return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
		}

		public override MemberTypes MemberType {
			get {
				return MemberTypes.TypeInfo;
			}
		}

		public override string Name {
			get {
				MonoTypeInfo info;
				get_type_info (_impl, out info);
				return info.name;
			}
		}

		public override string Namespace {
			get {
				MonoTypeInfo info;
				get_type_info (_impl, out info);
				return info.name_space;
			}
		}

		public override Module Module {
			get {
				return null;
			}
		}

		public override Type ReflectedType {
			get {
				return null;
			}
		}

		public override RuntimeTypeHandle TypeHandle {
			get {
				return _impl;
			}
		}

		public override int GetArrayRank ()
		{
			MonoTypeInfo info;
			
			get_type_info (_impl, out info);
			return info.rank;
		}
	}
}