public static StackObject *GetType(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj) { var p = esp - 1; AppDomain dommain = intp.AppDomain; string fullname = (string)StackObject.ToObject(p, dommain, mStack);; intp.Free(p); var t = intp.AppDomain.GetType(fullname); if (t != null) { return(ILIntepreter.PushObject(p, mStack, t.ReflectionType)); } else { return(ILIntepreter.PushNull(p)); } }
/*public static object CreateInstance(ILContext ctx, object instance, object[] param, IType[] genericArguments) * { * if (genericArguments != null && genericArguments.Length == 1) * { * var t = genericArguments[0]; * if (t is ILType) * { * return ((ILType)t).Instantiate(); * } * else * return Activator.CreateInstance(t.TypeForCLR); * } * else * throw new EntryPointNotFoundException(); * }*/ public static StackObject *CreateInstance2(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj) { var p = esp - 1; var t = mStack[p->Value] as Type; intp.Free(p); if (t != null) { if (t is ILRuntimeType) { return(ILIntepreter.PushObject(p, mStack, ((ILRuntimeType)t).ILType.Instantiate())); } else { return(ILIntepreter.PushObject(p, mStack, Activator.CreateInstance(t))); } } else { return(ILIntepreter.PushNull(p)); } }
/*public static object GetTypeFromHandle(ILContext ctx, object instance, object[] param, IType[] genericArguments) * { * return param[0]; * }*/ public unsafe static StackObject *MethodInfoInvoke(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj) { AppDomain domain = intp.AppDomain; //Don't ask me why not esp - 3, unity won't return the right result var ret = ILIntepreter.Minus(esp, 3); var param = esp - 1; var p = StackObject.ToObject(param, domain, mStack); intp.Free(param); param = esp - 1 - 1; var obj = StackObject.ToObject(param, domain, mStack); intp.Free(param); param = ILIntepreter.Minus(esp, 3); object instance = CheckCrossBindingAdapter(StackObject.ToObject(param, domain, mStack)); intp.Free(param); if (instance is ILRuntimeMethodInfo) { if (obj != null) { esp = ILIntepreter.PushObject(ret, mStack, obj); } else { esp = ret; } var ilmethod = ((ILRuntimeMethodInfo)instance).ILMethod; if (p != null) { object[] arr = (object[])p; for (int i = 0; i < ilmethod.ParameterCount; i++) { esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(arr[i])); } } bool unhandled; ret = intp.Execute(ilmethod, esp, out unhandled); ILRuntimeMethodInfo imi = (ILRuntimeMethodInfo)instance; var rt = imi.ILMethod.ReturnType; if (rt != domain.VoidType) { var res = ret - 1; if (res->ObjectType < ObjectTypes.Object) { return(ILIntepreter.PushObject(res, mStack, rt.TypeForCLR.CheckCLRTypes(StackObject.ToObject(res, domain, mStack)), true)); } else { return(ret); } } else { return(ILIntepreter.PushNull(ret)); } } else { return(ILIntepreter.PushObject(ret, mStack, ((MethodInfo)instance).Invoke(obj, (object[])p))); } }
/*public unsafe static object ObjectGetType(ILContext ctx, object instance, object[] param, IType[] genericArguments) * { * var type = instance.GetType(); * if (type == typeof(ILTypeInstance)) * { * return ((ILTypeInstance)instance).Type.ReflectionType; * } * else * return type; * }*/ public static StackObject *EnumParse(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj) { var ret = esp - 1 - 1; AppDomain domain = intp.AppDomain; var p = esp - 1; string name = (string)StackObject.ToObject(p, domain, mStack); intp.Free(p); p = esp - 1 - 1; Type t = (Type)StackObject.ToObject(p, domain, mStack); intp.Free(p); if (t is ILRuntimeType) { ILType it = ((ILRuntimeType)t).ILType; if (it.IsEnum) { var fields = it.TypeDefinition.Fields; for (int i = 0; i < fields.Count; i++) { var f = fields[i]; if (f.IsStatic) { if (f.Name == name) { ILEnumTypeInstance ins = new ILEnumTypeInstance(it); ins[0] = f.Constant; ins.Boxed = true; return(ILIntepreter.PushObject(ret, mStack, ins, true)); } else { int val; if (int.TryParse(name, out val)) { if ((int)f.Constant == val) { ILEnumTypeInstance ins = new ILEnumTypeInstance(it); ins[0] = f.Constant; ins.Boxed = true; return(ILIntepreter.PushObject(ret, mStack, ins, true)); } } } } } return(ILIntepreter.PushNull(ret)); } else { throw new Exception(string.Format("{0} is not Enum", t.FullName)); } } else if (t is ILRuntimeWrapperType) { return(ILIntepreter.PushObject(ret, mStack, Enum.Parse(((ILRuntimeWrapperType)t).RealType, name), true)); } else { return(ILIntepreter.PushObject(ret, mStack, Enum.Parse(t, name), true)); } }