2 // System.Reflection.MonoGenericClass
4 // Sean MacIsaac (macisaac@ximian.com)
5 // Paolo Molaro (lupus@ximian.com)
6 // Patrik Torstensson (patrik.torstensson@labs2.com)
8 // (C) 2001 Ximian, Inc.
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:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
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
;
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
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
;
57 #pragma warning restore 649
60 Hashtable fields
, ctors
, methods
;
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
{
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
;
99 return generic_type
.GetEvents (flags
);
101 return tb
.GetEvents_internal (flags
);
104 ConstructorInfo
[] GetConstructorsFromGTD (BindingFlags flags
)
106 TypeBuilder tb
= generic_type
as TypeBuilder
;
108 return generic_type
.GetConstructors (flags
);
110 return tb
.GetConstructorsInternal (flags
);
113 MethodInfo
[] GetMethodsFromGTD (BindingFlags bf
)
115 TypeBuilder tb
= generic_type
as TypeBuilder
;
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
);
126 FieldInfo
[] GetFieldsFromGTD (BindingFlags bf
)
128 TypeBuilder tb
= generic_type
as TypeBuilder
;
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
);
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
;
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
);
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
;
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);
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 ();
179 static PropertyInfo
[] GetPropertiesInternal (Type type
, BindingFlags bf
)
181 TypeBuilder tb
= type
as TypeBuilder
;
183 return tb
.properties
;
184 return type
.GetProperties (bf
);
187 Type
[] GetInterfacesFromGTD ()
189 TypeBuilder tb
= generic_type
as TypeBuilder
;
191 return tb
.interfaces
;
192 return generic_type
.GetInterfaces ();
195 internal bool IsCreated
{
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
;
210 MonoGenericClass parent
= GetParentType () as MonoGenericClass
;
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
),
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
)
244 if (!type
.IsGenericParameter
&& !type
.ContainsGenericParameters
)
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
];
252 return InflateType (type
.GetElementType (), type_args
, method_args
).MakePointerType ();
254 return InflateType (type
.GetElementType (), type_args
, method_args
).MakeByRefType ();
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 ("[*]"))
261 if (type
.ToString ().EndsWith ("[*]", StringComparison
.Ordinal
)) /*FIXME, the reflection API doesn't offer a way around this*/
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
{
277 Type parent
= GetParentType ();
278 return parent
!= null ? parent
: generic_type
.BaseType
;
282 Type
[] GetInterfacesInternal ()
284 Type
[] ifaces
= GetInterfacesFromGTD ();
287 Type
[] res
= new Type
[ifaces
.Length
];
288 for (int i
= 0; i
< res
.Length
; ++i
)
289 res
[i
] = InflateType (ifaces
[i
]);
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
)
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
)
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
)
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
356 Type current_type
= this;
358 MonoGenericClass gi
= current_type
as MonoGenericClass
;
360 l
.AddRange (gi
.GetMethodsInternal (bf
, this));
361 else if (current_type
is TypeBuilder
)
362 l
.AddRange (current_type
.GetMethods (bf
));
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));
372 if ((bf
& BindingFlags
.DeclaredOnly
) != 0)
374 current_type
= current_type
.BaseType
;
375 } while (current_type
!= null);
377 MethodInfo
[] result
= new MethodInfo
[l
.Count
];
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 ();
390 MethodAttributes mattrs
;
394 for (int i
= 0; i
< methods
.Length
; ++i
) {
395 MethodInfo c
= methods
[i
];
398 mattrs
= c
.Attributes
;
399 if ((mattrs
& MethodAttributes
.MemberAccessMask
) == MethodAttributes
.Public
) {
400 if ((bf
& BindingFlags
.Public
) != 0)
403 if ((bf
& BindingFlags
.NonPublic
) != 0)
409 if ((mattrs
& MethodAttributes
.Static
) != 0) {
410 if ((bf
& BindingFlags
.Static
) != 0)
413 if ((bf
& BindingFlags
.Instance
) != 0)
418 c
= TypeBuilder
.GetMethod (this, c
);
422 MethodInfo
[] result
= new MethodInfo
[l
.Count
];
427 public override ConstructorInfo
[] GetConstructors (BindingFlags bf
)
429 if (!IsCompilerContext
)
430 throw new NotSupportedException ();
432 ArrayList l
= new ArrayList ();
434 Type current_type
= this;
436 MonoGenericClass gi
= current_type
as MonoGenericClass
;
438 l
.AddRange (gi
.GetConstructorsInternal (bf
, this));
439 else if (current_type
is TypeBuilder
)
440 l
.AddRange (current_type
.GetConstructors (bf
));
442 MonoType mt
= (MonoType
) current_type
;
443 l
.AddRange (mt
.GetConstructors_internal (bf
, this));
447 if ((bf
& BindingFlags
.DeclaredOnly
) != 0)
449 current_type
= current_type
.BaseType
;
450 } while (current_type
!= null);
452 ConstructorInfo
[] result
= new ConstructorInfo
[l
.Count
];
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 ();
465 MethodAttributes mattrs
;
469 for (int i
= 0; i
< ctors
.Length
; i
++) {
470 ConstructorInfo c
= ctors
[i
];
473 mattrs
= c
.Attributes
;
474 if ((mattrs
& MethodAttributes
.MemberAccessMask
) == MethodAttributes
.Public
) {
475 if ((bf
& BindingFlags
.Public
) != 0)
478 if ((bf
& BindingFlags
.NonPublic
) != 0)
484 if ((mattrs
& MethodAttributes
.Static
) != 0) {
485 if ((bf
& BindingFlags
.Static
) != 0)
488 if ((bf
& BindingFlags
.Instance
) != 0)
493 l
.Add (TypeBuilder
.GetConstructor (this, c
));
496 ConstructorInfo
[] result
= new ConstructorInfo
[l
.Count
];
501 public override FieldInfo
[] GetFields (BindingFlags bf
)
503 if (!IsCompilerContext
)
504 throw new NotSupportedException ();
506 ArrayList l
= new ArrayList ();
508 Type current_type
= this;
510 MonoGenericClass gi
= current_type
as MonoGenericClass
;
512 l
.AddRange (gi
.GetFieldsInternal (bf
, this));
513 else if (current_type
is TypeBuilder
)
514 l
.AddRange (current_type
.GetFields (bf
));
516 MonoType mt
= (MonoType
) current_type
;
517 l
.AddRange (mt
.GetFields_internal (bf
, this));
521 if ((bf
& BindingFlags
.DeclaredOnly
) != 0)
523 current_type
= current_type
.BaseType
;
524 } while (current_type
!= null);
526 FieldInfo
[] result
= new FieldInfo
[l
.Count
];
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 ();
539 FieldAttributes fattrs
;
543 for (int i
= 0; i
< fields
.Length
; i
++) {
544 FieldInfo c
= fields
[i
];
547 fattrs
= c
.Attributes
;
548 if ((fattrs
& FieldAttributes
.FieldAccessMask
) == FieldAttributes
.Public
) {
549 if ((bf
& BindingFlags
.Public
) != 0)
552 if ((bf
& BindingFlags
.NonPublic
) != 0)
558 if ((fattrs
& FieldAttributes
.Static
) != 0) {
559 if ((bf
& BindingFlags
.Static
) != 0)
562 if ((bf
& BindingFlags
.Instance
) != 0)
567 l
.Add (TypeBuilder
.GetField (this, c
));
570 FieldInfo
[] result
= new FieldInfo
[l
.Count
];
575 public override PropertyInfo
[] GetProperties (BindingFlags bf
)
577 if (!IsCompilerContext
)
578 throw new NotSupportedException ();
580 ArrayList l
= new ArrayList ();
582 Type current_type
= this;
584 MonoGenericClass gi
= current_type
as MonoGenericClass
;
586 l
.AddRange (gi
.GetPropertiesInternal (bf
, this));
587 else if (current_type
is TypeBuilder
)
588 l
.AddRange (current_type
.GetProperties (bf
));
590 MonoType mt
= (MonoType
) current_type
;
591 l
.AddRange (mt
.GetPropertiesByName (null, bf
, false, this));
595 if ((bf
& BindingFlags
.DeclaredOnly
) != 0)
597 current_type
= current_type
.BaseType
;
598 } while (current_type
!= null);
600 PropertyInfo
[] result
= new PropertyInfo
[l
.Count
];
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 ();
613 MethodAttributes mattrs
;
618 foreach (PropertyInfo pinfo
in props
) {
620 accessor
= pinfo
.GetGetMethod (true);
621 if (accessor
== null)
622 accessor
= pinfo
.GetSetMethod (true);
623 if (accessor
== null)
625 mattrs
= accessor
.Attributes
;
626 if ((mattrs
& MethodAttributes
.MemberAccessMask
) == MethodAttributes
.Public
) {
627 if ((bf
& BindingFlags
.Public
) != 0)
630 if ((bf
& BindingFlags
.NonPublic
) != 0)
636 if ((mattrs
& MethodAttributes
.Static
) != 0) {
637 if ((bf
& BindingFlags
.Static
) != 0)
640 if ((bf
& BindingFlags
.Instance
) != 0)
645 l
.Add (new PropertyOnTypeBuilderInst (reftype
, pinfo
));
647 PropertyInfo
[] result
= new PropertyInfo
[l
.Count
];
652 public override EventInfo
[] GetEvents (BindingFlags bf
)
654 if (!IsCompilerContext
)
655 throw new NotSupportedException ();
657 ArrayList l
= new ArrayList ();
659 Type current_type
= this;
661 MonoGenericClass gi
= current_type
as MonoGenericClass
;
663 l
.AddRange (gi
.GetEventsInternal (bf
, this));
664 else if (current_type
is TypeBuilder
)
665 l
.AddRange (current_type
.GetEvents (bf
));
667 MonoType mt
= (MonoType
) current_type
;
668 l
.AddRange (mt
.GetEvents (bf
));
672 if ((bf
& BindingFlags
.DeclaredOnly
) != 0)
674 current_type
= current_type
.BaseType
;
675 } while (current_type
!= null);
677 EventInfo
[] result
= new EventInfo
[l
.Count
];
682 EventInfo
[] GetEventsInternal (BindingFlags bf
, MonoGenericClass reftype
) {
683 TypeBuilder tb
= generic_type
as TypeBuilder
;
685 EventInfo
[] res
= generic_type
.GetEvents (bf
);
686 for (int i
= 0; i
< res
.Length
; ++i
)
687 res
[i
] = new EventOnTypeBuilderInst (this, res
[i
]);
690 EventBuilder
[] events
= tb
.events
;
692 if (events
== null || events
.Length
== 0)
693 return new EventInfo
[0];
697 ArrayList l
= new ArrayList ();
699 MethodAttributes mattrs
;
702 for (int i
= 0; i
< event_count
; ++i
) {
703 EventBuilder ev
= events
[i
];
706 accessor
= ev
.add_method
;
707 if (accessor
== null)
708 accessor
= ev
.remove_method
;
709 if (accessor
== null)
711 mattrs
= accessor
.Attributes
;
712 if ((mattrs
& MethodAttributes
.MemberAccessMask
) == MethodAttributes
.Public
) {
713 if ((bf
& BindingFlags
.Public
) != 0)
716 if ((bf
& BindingFlags
.NonPublic
) != 0)
722 if ((mattrs
& MethodAttributes
.Static
) != 0) {
723 if ((bf
& BindingFlags
.Static
) != 0)
726 if ((bf
& BindingFlags
.Instance
) != 0)
731 l
.Add (new EventOnTypeBuilderInst (this, ev
));
733 EventInfo
[] result
= new EventInfo
[l
.Count
];
738 public override Type
[] GetNestedTypes (BindingFlags bf
)
740 return generic_type
.GetNestedTypes (bf
);
743 public override bool IsAssignableFrom (Type c
)
748 Type
[] interfaces
= GetInterfacesInternal ();
751 if (interfaces
== null)
753 foreach (Type t
in interfaces
)
754 if (c
.IsAssignableFrom (t
))
759 Type parent
= GetParentType ();
761 return c
== typeof (object);
763 return c
.IsAssignableFrom (parent
);
766 public override Type UnderlyingSystemType
{
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
;
804 for (int i
= 0; i
< type_arguments
.Length
; ++i
) {
810 string assemblyName
= type_arguments
[i
].Assembly
.FullName
;
811 name
= type_arguments
[i
].FullName
;
812 if (name
!= null && assemblyName
!= null)
813 name
= name
+ ", " + assemblyName
;
815 name
= type_arguments
[i
].ToString ();
818 if (compiler_ctx
&& type_arguments
[i
].IsGenericParameter
)
819 name
= type_arguments
[i
].Name
;
830 if (assembly_qualified
) {
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 ()
847 public override Type
[] GetGenericArguments ()
849 Type
[] ret
= new Type
[type_arguments
.Length
];
850 type_arguments
.CopyTo (ret
, 0);
854 public override bool ContainsGenericParameters
{
856 /*FIXME remove this once compound types are not instantiated using MGC*/
858 return GetElementType ().ContainsGenericParameters
;
860 foreach (Type t
in type_arguments
) {
861 if (t
.ContainsGenericParameters
)
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
{
882 if (!IsCompilerContext
)
883 throw new NotSupportedException ();
888 public override Type
MakeArrayType ()
890 return new ArrayType (this, 0);
893 public override Type
MakeArrayType (int rank
)
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 ()
920 protected override bool IsCOMObjectImpl ()
925 protected override bool IsPrimitiveImpl ()
930 protected override bool IsArrayImpl ()
935 protected override bool IsByRefImpl ()
940 protected override bool IsPointerImpl ()
945 protected override TypeAttributes
GetAttributeFlagsImpl ()
947 return generic_type
.Attributes
;
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
)
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
,
1005 CallingConventions callConvention
,
1007 ParameterModifier
[] modifiers
)
1009 if (!IsCompilerContext
)
1010 throw new NotSupportedException ();
1011 return MonoType
.GetConstructorImpl (GetConstructors (bindingAttr
), bindingAttr
, binder
, callConvention
, types
, modifiers
);
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
);