2009-12-14 Rodrigo Kumpera <rkumpera@novell.com>
[mono-project/dkf.git] / mcs / class / corlib / System.Reflection / MonoGenericClass.cs
blobe0ab79de07af71375422e109db61fd4932335e8f
1 //
2 // System.Reflection.MonoGenericClass
3 //
4 // Sean MacIsaac (macisaac@ximian.com)
5 // Paolo Molaro (lupus@ximian.com)
6 // Patrik Torstensson (patrik.torstensson@labs2.com)
7 //
8 // (C) 2001 Ximian, Inc.
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Reflection;
35 using System.Reflection.Emit;
36 using System.Collections;
37 using System.Runtime.CompilerServices;
38 using System.Globalization;
39 using System.Runtime.Serialization;
40 using System.Text;
42 namespace System.Reflection
45 * MonoGenericClass represents an instantiation of a generic TypeBuilder. MS
46 * calls this class TypeBuilderInstantiation (a much better name). MS returns
47 * NotImplementedException for many of the methods but we can't do that as gmcs
48 * depends on them.
50 internal class MonoGenericClass : Type
52 #region Keep in sync with object-internals.h
53 #pragma warning disable 649
54 internal Type generic_type;
55 Type[] type_arguments;
56 bool initialized;
57 #pragma warning restore 649
58 #endregion
60 Hashtable fields, ctors, methods;
61 int event_count;
62 int is_compiler_context;
64 internal MonoGenericClass ()
66 // this should not be used
67 throw new InvalidOperationException ();
70 internal MonoGenericClass (Type tb, Type[] args)
72 this.generic_type = tb;
73 this.type_arguments = args;
74 register_with_runtime (this); /*Temporary hack while*/
78 internal override bool IsCompilerContext {
79 get {
80 if (is_compiler_context == 0) {
81 bool is_cc = generic_type.IsCompilerContext;
82 foreach (Type t in type_arguments)
83 is_cc |= t.IsCompilerContext;
84 is_compiler_context = is_cc ? 1 : -1;
86 return is_compiler_context == 1;
90 [MethodImplAttribute(MethodImplOptions.InternalCall)]
91 extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
93 [MethodImplAttribute(MethodImplOptions.InternalCall)]
94 internal static extern void register_with_runtime (Type type);
96 EventInfo[] GetEventsFromGTD (BindingFlags flags) {
97 TypeBuilder tb = generic_type as TypeBuilder;
98 if (tb == null)
99 return generic_type.GetEvents (flags);
101 return tb.GetEvents_internal (flags);
104 ConstructorInfo[] GetConstructorsFromGTD (BindingFlags flags)
106 TypeBuilder tb = generic_type as TypeBuilder;
107 if (tb == null)
108 return generic_type.GetConstructors (flags);
110 return tb.GetConstructorsInternal (flags);
113 MethodInfo[] GetMethodsFromGTD (BindingFlags bf)
115 TypeBuilder tb = generic_type as TypeBuilder;
116 if (tb == null)
117 return generic_type.GetMethods (bf);
119 MethodInfo[] res = new MethodInfo [tb.num_methods];
120 if (tb.num_methods > 0)
121 Array.Copy (tb.methods, res, tb.num_methods);
123 return res;
126 FieldInfo[] GetFieldsFromGTD (BindingFlags bf)
128 TypeBuilder tb = generic_type as TypeBuilder;
129 if (tb == null)
130 return generic_type.GetFields (bf);
132 FieldInfo[] res = new FieldInfo [tb.num_fields];
133 if (tb.num_fields > 0)
134 Array.Copy (tb.fields, res, tb.num_fields);
136 return res;
139 /*@hint might not be honored so it required aditional filtering
140 TODO move filtering into here for the TypeBuilder case and remove the hint ugliness
142 MethodInfo[] GetMethodsFromGTDWithHint (BindingFlags hint)
144 TypeBuilder tb = generic_type as TypeBuilder;
145 if (tb == null)
146 return generic_type.GetMethods (hint);
148 if (tb.num_methods == 0)
149 return new MethodInfo [0];
150 MethodInfo[] res = new MethodInfo [tb.num_methods];
151 Array.Copy (tb.methods, 0, res, 0, tb.num_methods);
152 return res;
155 /*@hint might not be honored so it required aditional filtering
156 TODO move filtering into here for the TypeBuilder case and remove the hint ugliness
158 ConstructorInfo[] GetConstructorsFromGTDWithHint (BindingFlags hint)
160 TypeBuilder tb = generic_type as TypeBuilder;
161 if (tb == null)
162 return generic_type.GetConstructors (hint);
164 if (tb.ctors == null)
165 return new ConstructorInfo [0];
166 ConstructorInfo[] res = new ConstructorInfo [tb.ctors.Length];
167 tb.ctors.CopyTo (res, 0);
168 return res;
171 static Type PeelType (Type t) {
172 if (t.HasElementType)
173 return PeelType (t.GetElementType ());
174 if (t.IsGenericType && !t.IsGenericParameter)
175 return t.GetGenericTypeDefinition ();
176 return t;
179 static PropertyInfo[] GetPropertiesInternal (Type type, BindingFlags bf)
181 TypeBuilder tb = type as TypeBuilder;
182 if (tb != null)
183 return tb.properties;
184 return type.GetProperties (bf);
187 Type[] GetInterfacesFromGTD ()
189 TypeBuilder tb = generic_type as TypeBuilder;
190 if (tb != null)
191 return tb.interfaces;
192 return generic_type.GetInterfaces ();
195 internal bool IsCreated {
196 get {
197 TypeBuilder tb = generic_type as TypeBuilder;
198 return tb != null ? tb.is_created : true;
202 private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
203 BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
205 void initialize ()
207 if (initialized)
208 return;
210 MonoGenericClass parent = GetParentType () as MonoGenericClass;
211 if (parent != null)
212 parent.initialize ();
213 EventInfo[] events = GetEventsFromGTD (flags);
214 event_count = events.Length;
216 initialize (generic_type.GetMethods (flags),
217 GetConstructorsFromGTD (flags),
218 generic_type.GetFields (flags),
219 generic_type.GetProperties (flags),
220 events);
222 initialized = true;
225 Type GetParentType ()
227 return InflateType (generic_type.BaseType);
230 internal Type InflateType (Type type)
232 return InflateType (type, type_arguments, null);
235 internal Type InflateType (Type type, Type[] method_args)
237 return InflateType (type, type_arguments, method_args);
240 internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
242 if (type == null)
243 return null;
244 if (!type.IsGenericParameter && !type.ContainsGenericParameters)
245 return type;
246 if (type.IsGenericParameter) {
247 if (type.DeclaringMethod == null)
248 return type_args == null ? type : type_args [type.GenericParameterPosition];
249 return method_args == null ? type : method_args [type.GenericParameterPosition];
251 if (type.IsPointer)
252 return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
253 if (type.IsByRef)
254 return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
255 if (type.IsArray) {
256 if (type.GetArrayRank () > 1)
257 return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
258 #if BOOTSTRAP_NET_2_0
259 if (type.ToString ().EndsWith ("[*]"))
260 #else
261 if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
262 #endif
263 return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
264 return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
267 Type[] args = type.GetGenericArguments ();
268 for (int i = 0; i < args.Length; ++i)
269 args [i] = InflateType (args [i], type_args, method_args);
271 Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
272 return gtd.MakeGenericType (args);
275 public override Type BaseType {
276 get {
277 Type parent = GetParentType ();
278 return parent != null ? parent : generic_type.BaseType;
282 Type[] GetInterfacesInternal ()
284 Type[] ifaces = GetInterfacesFromGTD ();
285 if (ifaces == null)
286 return new Type [0];
287 Type[] res = new Type [ifaces.Length];
288 for (int i = 0; i < res.Length; ++i)
289 res [i] = InflateType (ifaces [i]);
290 return res;
293 public override Type[] GetInterfaces ()
295 if (!IsCompilerContext) {
296 Console.WriteLine ("--FAIL {0}", this);
297 Console.WriteLine ("\tgt {0}/{1}/{2}", generic_type, generic_type.IsCompilerContext, generic_type.GetType ());
299 foreach (Type t in type_arguments)
300 Console.WriteLine ("\targ {0}/{1}/{2}", t, t.IsCompilerContext, t.GetType ());
302 throw new NotSupportedException ();
304 return GetInterfacesInternal ();
307 protected override bool IsValueTypeImpl ()
309 return generic_type.IsValueType;
312 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
314 initialize ();
316 if (methods == null)
317 methods = new Hashtable ();
318 if (!methods.ContainsKey (fromNoninstanciated))
319 methods [fromNoninstanciated] = new MethodOnTypeBuilderInst (this, fromNoninstanciated);
320 return (MethodInfo)methods [fromNoninstanciated];
323 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
325 initialize ();
327 if (ctors == null)
328 ctors = new Hashtable ();
329 if (!ctors.ContainsKey (fromNoninstanciated))
330 ctors [fromNoninstanciated] = new ConstructorOnTypeBuilderInst (this, fromNoninstanciated);
331 return (ConstructorInfo)ctors [fromNoninstanciated];
334 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
336 initialize ();
337 if (fields == null)
338 fields = new Hashtable ();
339 if (!fields.ContainsKey (fromNoninstanciated))
340 fields [fromNoninstanciated] = new FieldOnTypeBuilderInst (this, fromNoninstanciated);
341 return (FieldInfo)fields [fromNoninstanciated];
344 public override MethodInfo[] GetMethods (BindingFlags bf)
346 if (!IsCompilerContext)
347 throw new NotSupportedException ();
349 ArrayList l = new ArrayList ();
352 // Walk up our class hierarchy and retrieve methods from our
353 // parent classes.
356 Type current_type = this;
357 do {
358 MonoGenericClass gi = current_type as MonoGenericClass;
359 if (gi != null)
360 l.AddRange (gi.GetMethodsInternal (bf, this));
361 else if (current_type is TypeBuilder)
362 l.AddRange (current_type.GetMethods (bf));
363 else {
364 // If we encounter a `MonoType', its
365 // GetMethodsByName() will return all the methods
366 // from its parent type(s), so we can stop here.
367 MonoType mt = (MonoType) current_type;
368 l.AddRange (mt.GetMethodsByName (null, bf, false, this));
369 break;
372 if ((bf & BindingFlags.DeclaredOnly) != 0)
373 break;
374 current_type = current_type.BaseType;
375 } while (current_type != null);
377 MethodInfo[] result = new MethodInfo [l.Count];
378 l.CopyTo (result);
379 return result;
382 MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
384 MethodInfo[] methods = GetMethodsFromGTDWithHint (bf);
385 if (methods.Length == 0)
386 return new MethodInfo [0];
388 ArrayList l = new ArrayList ();
389 bool match;
390 MethodAttributes mattrs;
392 initialize ();
394 for (int i = 0; i < methods.Length; ++i) {
395 MethodInfo c = methods [i];
397 match = false;
398 mattrs = c.Attributes;
399 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
400 if ((bf & BindingFlags.Public) != 0)
401 match = true;
402 } else {
403 if ((bf & BindingFlags.NonPublic) != 0)
404 match = true;
406 if (!match)
407 continue;
408 match = false;
409 if ((mattrs & MethodAttributes.Static) != 0) {
410 if ((bf & BindingFlags.Static) != 0)
411 match = true;
412 } else {
413 if ((bf & BindingFlags.Instance) != 0)
414 match = true;
416 if (!match)
417 continue;
418 c = TypeBuilder.GetMethod (this, c);
419 l.Add (c);
422 MethodInfo[] result = new MethodInfo [l.Count];
423 l.CopyTo (result);
424 return result;
427 public override ConstructorInfo[] GetConstructors (BindingFlags bf)
429 if (!IsCompilerContext)
430 throw new NotSupportedException ();
432 ArrayList l = new ArrayList ();
434 Type current_type = this;
435 do {
436 MonoGenericClass gi = current_type as MonoGenericClass;
437 if (gi != null)
438 l.AddRange (gi.GetConstructorsInternal (bf, this));
439 else if (current_type is TypeBuilder)
440 l.AddRange (current_type.GetConstructors (bf));
441 else {
442 MonoType mt = (MonoType) current_type;
443 l.AddRange (mt.GetConstructors_internal (bf, this));
444 break;
447 if ((bf & BindingFlags.DeclaredOnly) != 0)
448 break;
449 current_type = current_type.BaseType;
450 } while (current_type != null);
452 ConstructorInfo[] result = new ConstructorInfo [l.Count];
453 l.CopyTo (result);
454 return result;
457 ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
459 ConstructorInfo[] ctors = GetConstructorsFromGTDWithHint (bf);
460 if (ctors == null || ctors.Length == 0)
461 return new ConstructorInfo [0];
463 ArrayList l = new ArrayList ();
464 bool match;
465 MethodAttributes mattrs;
467 initialize ();
469 for (int i = 0; i < ctors.Length; i++) {
470 ConstructorInfo c = ctors [i];
472 match = false;
473 mattrs = c.Attributes;
474 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
475 if ((bf & BindingFlags.Public) != 0)
476 match = true;
477 } else {
478 if ((bf & BindingFlags.NonPublic) != 0)
479 match = true;
481 if (!match)
482 continue;
483 match = false;
484 if ((mattrs & MethodAttributes.Static) != 0) {
485 if ((bf & BindingFlags.Static) != 0)
486 match = true;
487 } else {
488 if ((bf & BindingFlags.Instance) != 0)
489 match = true;
491 if (!match)
492 continue;
493 l.Add (TypeBuilder.GetConstructor (this, c));
496 ConstructorInfo[] result = new ConstructorInfo [l.Count];
497 l.CopyTo (result);
498 return result;
501 public override FieldInfo[] GetFields (BindingFlags bf)
503 if (!IsCompilerContext)
504 throw new NotSupportedException ();
506 ArrayList l = new ArrayList ();
508 Type current_type = this;
509 do {
510 MonoGenericClass gi = current_type as MonoGenericClass;
511 if (gi != null)
512 l.AddRange (gi.GetFieldsInternal (bf, this));
513 else if (current_type is TypeBuilder)
514 l.AddRange (current_type.GetFields (bf));
515 else {
516 MonoType mt = (MonoType) current_type;
517 l.AddRange (mt.GetFields_internal (bf, this));
518 break;
521 if ((bf & BindingFlags.DeclaredOnly) != 0)
522 break;
523 current_type = current_type.BaseType;
524 } while (current_type != null);
526 FieldInfo[] result = new FieldInfo [l.Count];
527 l.CopyTo (result);
528 return result;
531 FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
533 FieldInfo[] fields = GetFieldsFromGTD (bf);
534 if (fields.Length == 0)
535 return new FieldInfo [0];
537 ArrayList l = new ArrayList ();
538 bool match;
539 FieldAttributes fattrs;
541 initialize ();
543 for (int i = 0; i < fields.Length; i++) {
544 FieldInfo c = fields [i];
546 match = false;
547 fattrs = c.Attributes;
548 if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
549 if ((bf & BindingFlags.Public) != 0)
550 match = true;
551 } else {
552 if ((bf & BindingFlags.NonPublic) != 0)
553 match = true;
555 if (!match)
556 continue;
557 match = false;
558 if ((fattrs & FieldAttributes.Static) != 0) {
559 if ((bf & BindingFlags.Static) != 0)
560 match = true;
561 } else {
562 if ((bf & BindingFlags.Instance) != 0)
563 match = true;
565 if (!match)
566 continue;
567 l.Add (TypeBuilder.GetField (this, c));
570 FieldInfo[] result = new FieldInfo [l.Count];
571 l.CopyTo (result);
572 return result;
575 public override PropertyInfo[] GetProperties (BindingFlags bf)
577 if (!IsCompilerContext)
578 throw new NotSupportedException ();
580 ArrayList l = new ArrayList ();
582 Type current_type = this;
583 do {
584 MonoGenericClass gi = current_type as MonoGenericClass;
585 if (gi != null)
586 l.AddRange (gi.GetPropertiesInternal (bf, this));
587 else if (current_type is TypeBuilder)
588 l.AddRange (current_type.GetProperties (bf));
589 else {
590 MonoType mt = (MonoType) current_type;
591 l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
592 break;
595 if ((bf & BindingFlags.DeclaredOnly) != 0)
596 break;
597 current_type = current_type.BaseType;
598 } while (current_type != null);
600 PropertyInfo[] result = new PropertyInfo [l.Count];
601 l.CopyTo (result);
602 return result;
605 PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
607 PropertyInfo[] props = GetPropertiesInternal (generic_type, bf);
608 if (props == null || props.Length == 0)
609 return new PropertyInfo [0];
611 ArrayList l = new ArrayList ();
612 bool match;
613 MethodAttributes mattrs;
614 MethodInfo accessor;
616 initialize ();
618 foreach (PropertyInfo pinfo in props) {
619 match = false;
620 accessor = pinfo.GetGetMethod (true);
621 if (accessor == null)
622 accessor = pinfo.GetSetMethod (true);
623 if (accessor == null)
624 continue;
625 mattrs = accessor.Attributes;
626 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
627 if ((bf & BindingFlags.Public) != 0)
628 match = true;
629 } else {
630 if ((bf & BindingFlags.NonPublic) != 0)
631 match = true;
633 if (!match)
634 continue;
635 match = false;
636 if ((mattrs & MethodAttributes.Static) != 0) {
637 if ((bf & BindingFlags.Static) != 0)
638 match = true;
639 } else {
640 if ((bf & BindingFlags.Instance) != 0)
641 match = true;
643 if (!match)
644 continue;
645 l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
647 PropertyInfo[] result = new PropertyInfo [l.Count];
648 l.CopyTo (result);
649 return result;
652 public override EventInfo[] GetEvents (BindingFlags bf)
654 if (!IsCompilerContext)
655 throw new NotSupportedException ();
657 ArrayList l = new ArrayList ();
659 Type current_type = this;
660 do {
661 MonoGenericClass gi = current_type as MonoGenericClass;
662 if (gi != null)
663 l.AddRange (gi.GetEventsInternal (bf, this));
664 else if (current_type is TypeBuilder)
665 l.AddRange (current_type.GetEvents (bf));
666 else {
667 MonoType mt = (MonoType) current_type;
668 l.AddRange (mt.GetEvents (bf));
669 break;
672 if ((bf & BindingFlags.DeclaredOnly) != 0)
673 break;
674 current_type = current_type.BaseType;
675 } while (current_type != null);
677 EventInfo[] result = new EventInfo [l.Count];
678 l.CopyTo (result);
679 return result;
682 EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
683 TypeBuilder tb = generic_type as TypeBuilder;
684 if (tb == null) {
685 EventInfo[] res = generic_type.GetEvents (bf);
686 for (int i = 0; i < res.Length; ++i)
687 res [i] = new EventOnTypeBuilderInst (this, res [i]);
688 return res;
690 EventBuilder[] events = tb.events;
692 if (events == null || events.Length == 0)
693 return new EventInfo [0];
695 initialize ();
697 ArrayList l = new ArrayList ();
698 bool match;
699 MethodAttributes mattrs;
700 MethodInfo accessor;
702 for (int i = 0; i < event_count; ++i) {
703 EventBuilder ev = events [i];
705 match = false;
706 accessor = ev.add_method;
707 if (accessor == null)
708 accessor = ev.remove_method;
709 if (accessor == null)
710 continue;
711 mattrs = accessor.Attributes;
712 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
713 if ((bf & BindingFlags.Public) != 0)
714 match = true;
715 } else {
716 if ((bf & BindingFlags.NonPublic) != 0)
717 match = true;
719 if (!match)
720 continue;
721 match = false;
722 if ((mattrs & MethodAttributes.Static) != 0) {
723 if ((bf & BindingFlags.Static) != 0)
724 match = true;
725 } else {
726 if ((bf & BindingFlags.Instance) != 0)
727 match = true;
729 if (!match)
730 continue;
731 l.Add (new EventOnTypeBuilderInst (this, ev));
733 EventInfo[] result = new EventInfo [l.Count];
734 l.CopyTo (result);
735 return result;
738 public override Type[] GetNestedTypes (BindingFlags bf)
740 return generic_type.GetNestedTypes (bf);
743 public override bool IsAssignableFrom (Type c)
745 if (c == this)
746 return true;
748 Type[] interfaces = GetInterfacesInternal ();
750 if (c.IsInterface) {
751 if (interfaces == null)
752 return false;
753 foreach (Type t in interfaces)
754 if (c.IsAssignableFrom (t))
755 return true;
756 return false;
759 Type parent = GetParentType ();
760 if (parent == null)
761 return c == typeof (object);
762 else
763 return c.IsAssignableFrom (parent);
766 public override Type UnderlyingSystemType {
767 get { return this; }
770 public override Assembly Assembly {
771 get { return generic_type.Assembly; }
774 public override Module Module {
775 get { return generic_type.Module; }
778 public override string Name {
779 get { return generic_type.Name; }
782 public override string Namespace {
783 get { return generic_type.Namespace; }
786 public override string FullName {
787 get { return format_name (true, false); }
790 public override string AssemblyQualifiedName {
791 get { return format_name (true, true); }
794 public override Guid GUID {
795 get { throw new NotSupportedException (); }
798 string format_name (bool full_name, bool assembly_qualified)
800 StringBuilder sb = new StringBuilder (generic_type.FullName);
801 bool compiler_ctx = IsCompilerContext;
803 sb.Append ("[");
804 for (int i = 0; i < type_arguments.Length; ++i) {
805 if (i > 0)
806 sb.Append (",");
808 string name;
809 if (full_name) {
810 string assemblyName = type_arguments [i].Assembly.FullName;
811 name = type_arguments [i].FullName;
812 if (name != null && assemblyName != null)
813 name = name + ", " + assemblyName;
814 } else {
815 name = type_arguments [i].ToString ();
817 if (name == null) {
818 if (compiler_ctx && type_arguments [i].IsGenericParameter)
819 name = type_arguments [i].Name;
820 else
821 return null;
823 if (full_name)
824 sb.Append ("[");
825 sb.Append (name);
826 if (full_name)
827 sb.Append ("]");
829 sb.Append ("]");
830 if (assembly_qualified) {
831 sb.Append (", ");
832 sb.Append (generic_type.Assembly.FullName);
834 return sb.ToString ();
837 public override string ToString ()
839 return format_name (false, false);
842 public override Type GetGenericTypeDefinition ()
844 return generic_type;
847 public override Type[] GetGenericArguments ()
849 Type[] ret = new Type [type_arguments.Length];
850 type_arguments.CopyTo (ret, 0);
851 return ret;
854 public override bool ContainsGenericParameters {
855 get {
856 /*FIXME remove this once compound types are not instantiated using MGC*/
857 if (HasElementType)
858 return GetElementType ().ContainsGenericParameters;
860 foreach (Type t in type_arguments) {
861 if (t.ContainsGenericParameters)
862 return true;
864 return false;
868 public override bool IsGenericTypeDefinition {
869 get { return false; }
872 public override bool IsGenericType {
873 get { return !HasElementType; }
876 public override Type DeclaringType {
877 get { return InflateType (generic_type.DeclaringType); }
880 public override RuntimeTypeHandle TypeHandle {
881 get {
882 if (!IsCompilerContext)
883 throw new NotSupportedException ();
884 return _impl;
888 public override Type MakeArrayType ()
890 return new ArrayType (this, 0);
893 public override Type MakeArrayType (int rank)
895 if (rank < 1)
896 throw new IndexOutOfRangeException ();
897 return new ArrayType (this, rank);
900 public override Type MakeByRefType ()
902 return new ByRefType (this);
905 public override Type MakePointerType ()
907 return new PointerType (this);
910 public override Type GetElementType ()
912 throw new NotSupportedException ();
915 protected override bool HasElementTypeImpl ()
917 return false;
920 protected override bool IsCOMObjectImpl ()
922 return false;
925 protected override bool IsPrimitiveImpl ()
927 return false;
930 protected override bool IsArrayImpl ()
932 return false;
935 protected override bool IsByRefImpl ()
937 return false;
940 protected override bool IsPointerImpl ()
942 return false;
945 protected override TypeAttributes GetAttributeFlagsImpl ()
947 return generic_type.Attributes;
950 //stuff that throws
951 public override Type GetInterface (string name, bool ignoreCase)
953 throw new NotSupportedException ();
956 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
958 if (!IsCompilerContext)
959 throw new NotSupportedException ();
960 foreach (var evt in GetEvents (bindingAttr)) {
961 if (evt.Name == name)
962 return evt;
964 return null;
967 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
969 throw new NotSupportedException ();
972 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
974 throw new NotSupportedException ();
977 public override Type GetNestedType (string name, BindingFlags bindingAttr)
979 throw new NotSupportedException ();
982 public override object InvokeMember (string name, BindingFlags invokeAttr,
983 Binder binder, object target, object[] args,
984 ParameterModifier[] modifiers,
985 CultureInfo culture, string[] namedParameters)
987 throw new NotSupportedException ();
990 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
991 CallingConventions callConvention, Type[] types,
992 ParameterModifier[] modifiers)
994 throw new NotSupportedException ();
997 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
998 Type returnType, Type[] types, ParameterModifier[] modifiers)
1000 throw new NotSupportedException ();
1003 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
1004 Binder binder,
1005 CallingConventions callConvention,
1006 Type[] types,
1007 ParameterModifier[] modifiers)
1009 if (!IsCompilerContext)
1010 throw new NotSupportedException ();
1011 return MonoType.GetConstructorImpl (GetConstructors (bindingAttr), bindingAttr, binder, callConvention, types, modifiers);
1014 //MemberInfo
1015 public override bool IsDefined (Type attributeType, bool inherit)
1017 if (!IsCompilerContext)
1018 throw new NotSupportedException ();
1019 return generic_type.IsDefined (attributeType, inherit);
1022 public override object [] GetCustomAttributes (bool inherit)
1024 if (!IsCompilerContext)
1025 throw new NotSupportedException ();
1026 return generic_type.GetCustomAttributes (inherit);
1029 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
1031 if (!IsCompilerContext)
1032 throw new NotSupportedException ();
1033 return generic_type.GetCustomAttributes (attributeType, inherit);