| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- //
- // System.MonoType
- //
- // Sean MacIsaac ([email protected])
- // Paolo Molaro ([email protected])
- // Patrik Torstensson ([email protected])
- //
- // (C) 2001 Ximian, Inc.
- //
- using System.Reflection;
- using System.Collections;
- using System.Runtime.CompilerServices;
- using System.Globalization;
- using System.Runtime.Serialization;
- namespace System.Reflection
- {
- internal class MonoGenericInst : MonoType
- {
- private IntPtr klass;
- protected MonoGenericInst parent;
- protected Type generic_type;
- private MonoGenericInst[] interfaces;
- private MethodInfo[] methods;
- private ConstructorInfo[] ctors;
- private FieldInfo[] fields;
- [MonoTODO]
- internal MonoGenericInst ()
- : base (null)
- {
- // this should not be used
- throw new InvalidOperationException ();
- }
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern MethodInfo inflate_method (MonoGenericInst declaring, MonoGenericInst reflected, MethodInfo method);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern ConstructorInfo inflate_ctor (MonoGenericInst declaring, MonoGenericInst reflected, ConstructorInfo ctor);
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern FieldInfo inflate_field (MonoGenericInst declaring, MonoGenericInst reflected, FieldInfo field);
- private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
- BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
- protected void inflate (MonoGenericInst reflected,
- ArrayList mlist, ArrayList clist, ArrayList flist)
- {
- if (parent != null)
- parent.inflate (parent, mlist, clist, flist);
- else if (BaseType != null) {
- mlist.AddRange (generic_type.BaseType.GetMethods (flags));
- clist.AddRange (generic_type.BaseType.GetConstructors (flags));
- flist.AddRange (generic_type.BaseType.GetFields (flags));
- } else if (interfaces != null) {
- foreach (MonoGenericInst iface in interfaces) {
- if (iface != null)
- iface.inflate (iface, mlist, clist, flist);
- }
- }
- foreach (MethodInfo m in generic_type.GetMethods (flags))
- mlist.Add (inflate_method (this, reflected, m));
- foreach (ConstructorInfo c in generic_type.GetConstructors (flags))
- clist.Add (inflate_ctor (this, reflected, c));
- foreach (FieldInfo f in generic_type.GetFields (flags))
- flist.Add (inflate_field (this, reflected, f));
- }
- void initialize ()
- {
- ArrayList mlist = new ArrayList ();
- ArrayList clist = new ArrayList ();
- ArrayList flist = new ArrayList ();
- inflate (this, mlist, clist, flist);
- methods = new MethodInfo [mlist.Count];
- mlist.CopyTo (methods, 0);
- ctors = new ConstructorInfo [clist.Count];
- clist.CopyTo (ctors, 0);
- fields = new FieldInfo [flist.Count];
- flist.CopyTo (fields, 0);
- }
- public override Type BaseType {
- get { return parent != null ? parent : generic_type.BaseType; }
- }
- protected override bool IsValueTypeImpl ()
- {
- if (BaseType == null)
- return false;
- if (BaseType == typeof (Enum) || BaseType == typeof (ValueType))
- return true;
- return BaseType.IsSubclassOf (typeof (ValueType));
- }
- public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
- {
- if (methods == null)
- initialize ();
- return GetMethods_impl (bindingAttr);
- }
- protected MethodInfo[] GetMethods_impl (BindingFlags bindingAttr)
- {
- ArrayList l = new ArrayList ();
- bool match;
- MethodAttributes mattrs;
- foreach (MethodInfo c in methods) {
- match = false;
- mattrs = c.Attributes;
- if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- match = false;
- if ((mattrs & MethodAttributes.Static) != 0) {
- if ((bindingAttr & BindingFlags.Static) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.Instance) != 0)
- match = true;
- }
- if (!match)
- continue;
- l.Add (c);
- }
- MethodInfo[] result = new MethodInfo [l.Count];
- l.CopyTo (result);
- return result;
- }
- public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
- {
- if (ctors == null)
- initialize ();
- return GetConstructors_impl (bindingAttr);
- }
- protected ConstructorInfo[] GetConstructors_impl (BindingFlags bindingAttr)
- {
- ArrayList l = new ArrayList ();
- bool match;
- MethodAttributes mattrs;
- foreach (ConstructorInfo c in ctors) {
- match = false;
- mattrs = c.Attributes;
- if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- match = false;
- if ((mattrs & MethodAttributes.Static) != 0) {
- if ((bindingAttr & BindingFlags.Static) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.Instance) != 0)
- match = true;
- }
- if (!match)
- continue;
- l.Add (c);
- }
- ConstructorInfo[] result = new ConstructorInfo [l.Count];
- l.CopyTo (result);
- return result;
- }
- public override FieldInfo[] GetFields (BindingFlags bindingAttr)
- {
- if (fields == null)
- initialize ();
- return GetFields_impl (bindingAttr);
- }
- protected FieldInfo[] GetFields_impl (BindingFlags bindingAttr)
- {
- ArrayList l = new ArrayList ();
- bool match;
- FieldAttributes fattrs;
- foreach (FieldInfo c in fields) {
- match = false;
- fattrs = c.Attributes;
- if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
- if ((bindingAttr & BindingFlags.Public) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.NonPublic) != 0)
- match = true;
- }
- if (!match)
- continue;
- match = false;
- if ((fattrs & FieldAttributes.Static) != 0) {
- if ((bindingAttr & BindingFlags.Static) != 0)
- match = true;
- } else {
- if ((bindingAttr & BindingFlags.Instance) != 0)
- match = true;
- }
- if (!match)
- continue;
- l.Add (c);
- }
- FieldInfo[] result = new FieldInfo [l.Count];
- l.CopyTo (result);
- return result;
- }
- }
- internal class MonoInflatedMethod : MonoMethod
- {
- private readonly MethodInfo declaring;
- private readonly MonoGenericInst declaring_type;
- private readonly MonoGenericInst reflected_type;
- private readonly IntPtr ginst;
- public override Type DeclaringType {
- get {
- return declaring_type != null ? declaring_type : base.DeclaringType;
- }
- }
- public override Type ReflectedType {
- get {
- return reflected_type != null ? reflected_type : base.ReflectedType;
- }
- }
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- // FIXME
- return false;
- }
- public override object[] GetCustomAttributes (bool inherit)
- {
- // FIXME
- return new object [0];
- }
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- // FIXME
- return new object [0];
- }
- }
- internal class MonoInflatedCtor : MonoCMethod
- {
- private readonly ConstructorInfo declaring;
- private readonly MonoGenericInst declaring_type;
- private readonly MonoGenericInst reflected_type;
- private readonly IntPtr ginst;
- public override Type DeclaringType {
- get {
- return declaring_type != null ? declaring_type : base.DeclaringType;
- }
- }
- public override Type ReflectedType {
- get {
- return reflected_type != null ? reflected_type : base.ReflectedType;
- }
- }
- public override bool IsDefined (Type attributeType, bool inherit)
- {
- // FIXME
- return false;
- }
- public override object[] GetCustomAttributes (bool inherit)
- {
- // FIXME
- return new object [0];
- }
- public override object[] GetCustomAttributes (Type attributeType, bool inherit)
- {
- // FIXME
- return new object [0];
- }
- }
- internal class MonoInflatedField : MonoField
- {
- private readonly IntPtr dhandle;
- private readonly MonoGenericInst declaring_type;
- private readonly MonoGenericInst reflected_type;
- public override Type DeclaringType {
- get {
- return declaring_type != null ? declaring_type : base.DeclaringType;
- }
- }
- public override Type ReflectedType {
- get {
- return reflected_type != null ? reflected_type : base.ReflectedType;
- }
- }
- }
- internal class MonoGenericParam : MonoType
- {
- private object refobj;
- private int index;
- private string name;
- private int flags;
- private Type[] constraints;
- bool initialized;
- [MonoTODO]
- internal MonoGenericParam ()
- : base (null)
- {
- // this should not be used
- throw new InvalidOperationException ();
- }
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private extern void initialize ();
- public void SetConstraints (Type[] constraints)
- {
- this.constraints = constraints;
- initialize ();
- }
- public override Type BaseType {
- get {
- if (!initialized)
- throw new InvalidOperationException ();
- if ((constraints.Length == 0) || constraints [0].IsInterface)
- return null;
- else
- return constraints [0];
- }
- }
- public override Type[] GetInterfaces ()
- {
- if (!initialized)
- throw new InvalidOperationException ();
- if ((constraints.Length == 0) || constraints [0].IsInterface)
- return constraints;
- else {
- Type[] ret = new Type [constraints.Length-1];
- Array.Copy (constraints, 1, ret, 0, constraints.Length-1);
- return ret;
- }
- }
- }
- }
|