4 // Sean MacIsaac (macisaac@ximian.com)
5 // Paolo Molaro (lupus@ximian.com)
6 // Patrik Torstensson (patrik.torstensson@labs2.com)
8 // (C) 2001 Ximian, Inc.
11 using System.Reflection;
12 using System.Reflection.Emit;
13 using System.Collections;
14 using System.Runtime.CompilerServices;
15 using System.Globalization;
16 using System.Runtime.Serialization;
18 namespace System.Reflection
20 internal class MonoGenericInst : MonoType
22 protected Type generic_type;
26 internal MonoGenericInst ()
29 // this should not be used
30 throw new InvalidOperationException ();
33 [MethodImplAttribute(MethodImplOptions.InternalCall)]
34 protected extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields);
36 [MethodImplAttribute(MethodImplOptions.InternalCall)]
37 protected extern MethodInfo[] GetMethods_internal (Type reflected_type);
39 [MethodImplAttribute(MethodImplOptions.InternalCall)]
40 protected extern ConstructorInfo[] GetConstructors_internal (Type reflected_type);
42 [MethodImplAttribute(MethodImplOptions.InternalCall)]
43 protected extern FieldInfo[] GetFields_internal (Type reflected_type);
45 private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
46 BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
53 MonoGenericInst parent = GetParentType ();
57 initialize (generic_type.GetMethods (flags),
58 generic_type.GetConstructors (flags),
59 generic_type.GetFields (flags));
64 [MethodImplAttribute(MethodImplOptions.InternalCall)]
65 protected extern MonoGenericInst GetParentType ();
67 [MethodImplAttribute(MethodImplOptions.InternalCall)]
68 protected extern MonoGenericInst[] GetInterfaces_internal ();
70 public override Type BaseType {
72 MonoGenericInst parent = GetParentType ();
73 return parent != null ? parent : generic_type.BaseType;
77 public override Type DeclaringType {
78 get { return generic_type.DeclaringType; }
81 public override Type[] GetInterfaces ()
83 return GetInterfaces_internal ();
86 protected override bool IsValueTypeImpl ()
88 return generic_type.IsValueType;
91 public override MethodInfo[] GetMethods (BindingFlags bf)
94 return GetMethods_impl (bf, this);
97 protected MethodInfo[] GetMethods_impl (BindingFlags bf, Type reftype)
99 ArrayList l = new ArrayList ();
101 MethodAttributes mattrs;
103 if ((bf & BindingFlags.DeclaredOnly) == 0) {
104 MonoGenericInst parent = GetParentType ();
106 l.AddRange (parent.GetMethods_impl (bf, reftype));
109 MethodInfo[] methods = GetMethods_internal (reftype);
111 for (int i = 0; i < methods.Length; i++) {
112 MethodInfo c = methods [i];
115 mattrs = c.Attributes;
116 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
117 if ((bf & BindingFlags.Public) != 0)
120 if ((bf & BindingFlags.NonPublic) != 0)
126 if ((mattrs & MethodAttributes.Static) != 0) {
127 if ((bf & BindingFlags.Static) != 0)
130 if ((bf & BindingFlags.Instance) != 0)
137 MethodInfo[] result = new MethodInfo [l.Count];
142 public override ConstructorInfo[] GetConstructors (BindingFlags bf)
145 return GetConstructors_impl (bf, this);
148 protected ConstructorInfo[] GetConstructors_impl (BindingFlags bf, Type reftype)
150 ArrayList l = new ArrayList ();
152 MethodAttributes mattrs;
154 if ((bf & BindingFlags.DeclaredOnly) == 0) {
155 MonoGenericInst parent = GetParentType ();
157 l.AddRange (parent.GetConstructors_impl (bf, reftype));
160 ConstructorInfo[] ctors = GetConstructors_internal (reftype);
162 for (int i = 0; i < ctors.Length; i++) {
163 ConstructorInfo c = ctors [i];
166 mattrs = c.Attributes;
167 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
168 if ((bf & BindingFlags.Public) != 0)
171 if ((bf & BindingFlags.NonPublic) != 0)
177 if ((mattrs & MethodAttributes.Static) != 0) {
178 if ((bf & BindingFlags.Static) != 0)
181 if ((bf & BindingFlags.Instance) != 0)
188 ConstructorInfo[] result = new ConstructorInfo [l.Count];
193 public override FieldInfo[] GetFields (BindingFlags bf)
196 return GetFields_impl (bf, this);
199 protected FieldInfo[] GetFields_impl (BindingFlags bf, Type reftype)
201 ArrayList l = new ArrayList ();
203 FieldAttributes fattrs;
205 if ((bf & BindingFlags.DeclaredOnly) == 0) {
206 MonoGenericInst parent = GetParentType ();
208 l.AddRange (parent.GetFields_impl (bf, reftype));
211 FieldInfo[] fields = GetFields_internal (reftype);
213 for (int i = 0; i < fields.Length; i++) {
214 FieldInfo c = fields [i];
217 fattrs = c.Attributes;
218 if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
219 if ((bf & BindingFlags.Public) != 0)
222 if ((bf & BindingFlags.NonPublic) != 0)
228 if ((fattrs & FieldAttributes.Static) != 0) {
229 if ((bf & BindingFlags.Static) != 0)
232 if ((bf & BindingFlags.Instance) != 0)
239 FieldInfo[] result = new FieldInfo [l.Count];
245 internal class MonoGenericParam : MonoType
247 private object refobj;
251 private Type[] constraints;
255 internal MonoGenericParam ()
258 // this should not be used
259 throw new InvalidOperationException ();
262 [MethodImplAttribute(MethodImplOptions.InternalCall)]
263 private extern void initialize ();
265 public void SetConstraints (Type[] constraints)
267 this.constraints = constraints;
271 public override Type BaseType {
274 throw new InvalidOperationException ();
275 if ((constraints.Length == 0) || constraints [0].IsInterface)
278 return constraints [0];
282 public override Type[] GetInterfaces ()
285 throw new InvalidOperationException ();
287 if ((constraints.Length == 0) || constraints [0].IsInterface)
290 Type[] ret = new Type [constraints.Length-1];
291 Array.Copy (constraints, 1, ret, 0, constraints.Length-1);