/// <summary> /// 添加回调侦听 /// </summary> /// <param name="protocol">协议号</param> /// <param name="fun">回调方法</param> /// <param name="clrType">数据的CLR类型</param> public void addListener(int protocol, SocketListenerDele fun, ICLRType clrType) { if (!listenDic.ContainsKey(protocol)) { listenDic.Add(protocol, new SocketListenerVO(clrType, fun)); } }
public Type_Common_System(ICLRSharp_Environment env, System.Type type, ICLRType[] subtype) { this.env = env; this.TypeForSystem = type; FullNameWithAssembly = type.AssemblyQualifiedName; this.SubTypes = subtype; }
/// <summary> /// 发送命令 /// </summary> /// <param name="type">L#类型,必须是ICLRType的实现者</param> /// <param name="param">命令携带的参数</param> public void sendCommand(ICLRType clrType, object param) { if (disposed) { throw new Exception(clrType.FullName + "对象已经销毁,sendCommand失败"); } mvcCharge.sendCommand(clrType, param); }
public Method_Common_System(ICLRType DeclaringType, System.Reflection.MethodBase method) { if (method == null) throw new Exception("not allow null method."); method_System = method; this.DeclaringType = DeclaringType; if (method is System.Reflection.MethodInfo) { System.Reflection.MethodInfo info = method as System.Reflection.MethodInfo; ReturnType = DeclaringType.env.GetType(info.ReturnType); } ParamList = new MethodParamList(DeclaringType.env, method); }
//========================================================================================= /// <summary> /// 将ByteBuffer转化为实例 /// </summary> public static object byteBufferToClrObject(ref ByteBuffer buff, ICLRType clrType) { CLRSharp_Instance inst = CLRSharpManager.instance.creatCLRInstance(clrType) as CLRSharp_Instance; HashList<string, string> fieldInfos = CLRSharpManager.instance.Invoke(inst.type, "getFieldInfos", inst) as HashList<string, string>; string[] filedNames = fieldInfos.keys.ToArray(); for (int i = 0, len = filedNames.Length; i < len; i++) { inst.Fields[filedNames[i]] = getField(ref buff, fieldInfos.getValue(filedNames[i])); } return inst; }
public void RegType(ICLRType type) { mapType[type.FullName] = type; }
//得到类型的时候应该得到模块内Type或者真实Type //一个统一的Type,然后根据具体情况调用两边 public ICLRType GetType(string fullname, Mono.Cecil.ModuleDefinition module) { ICLRType type = null; bool b = mapType.TryGetValue(fullname, out type); if (!b) { List <ICLRType> subTypes = new List <ICLRType>(); if (fullname.Contains("<>"))//匿名类型 { string[] subts = fullname.Split('/'); ICLRType ft = GetType(subts[0], module); for (int i = 1; i < subts.Length; i++) { ft = ft.GetNestType(this, subts[i]); } return(ft); } string fullnameT = fullname.Replace('/', '+'); if (fullnameT.Contains("<")) { string outname = ""; int depth = 0; int lastsplitpos = 0; for (int i = 0; i < fullname.Length; i++) { string checkname = null; if (fullname[i] == '/') { } else if (fullname[i] == '<') { if (i != 0) { depth++; } if (depth == 1)// { lastsplitpos = i; outname += "["; continue; } } else if (fullname[i] == '>') { if (depth == 1) { checkname = fullnameT.Substring(lastsplitpos + 1, i - lastsplitpos - 1); var subtype = GetType(checkname, module); subTypes.Add(subtype); if (subtype is ICLRType_Sharp) { subtype = GetType(typeof(CLRSharp_Instance)); } outname += "[" + subtype.FullNameWithAssembly + "]"; lastsplitpos = i; } //if(depth>0) depth--; if (depth == 0) { outname += "]"; continue; } else if (depth < 0) { depth = 0; } } else if (fullname[i] == ',') { if (depth == 1) { checkname = fullnameT.Substring(lastsplitpos + 1, i - lastsplitpos - 1); var subtype = GetType(checkname, module); subTypes.Add(subtype); if (subtype is ICLRType_Sharp) { subtype = GetType(typeof(CLRSharp_Instance)); } outname += "[" + subtype.FullNameWithAssembly + "],"; lastsplitpos = i; } } if (depth == 0) { outname += fullnameT[i]; } } fullnameT = outname; // fullnameT = fullnameT.Replace('<', '['); //fullnameT = fullnameT.Replace('>', ']'); } System.Type t = System.Type.GetType(fullnameT); if (t == null && module != null && module.HasAssemblyReferences) { foreach (var rm in module.AssemblyReferences) { t = System.Type.GetType(fullnameT + "," + rm.Name); if (t != null) { fullnameT = fullnameT + "," + rm.Name; break; } } } if (t != null) { type = new Type_Common_System(this, t, fullnameT, subTypes.ToArray()); } mapType[fullname] = type; } return(type); }
public Type_Common_CLRSharp(ICLRSharp_Environment env, TypeDefinition type) { this.env = env; this.type_CLRSharp = type; bool isEnum = type.IsEnum; if (isEnum) { this._isenum = true; } bool flag = this.type_CLRSharp.BaseType != null; if (flag) { this.BaseType = env.GetType(this.type_CLRSharp.BaseType.FullName); bool flag2 = this.BaseType is ICLRType_System; if (flag2) { bool flag3 = this.BaseType.TypeForSystem == typeof(Enum) || this.BaseType.TypeForSystem == typeof(object) || this.BaseType.TypeForSystem == typeof(ValueType) || this.BaseType.TypeForSystem == typeof(Enum); if (!flag3) { env.logger.Log_Error("ScriptType:" + this.Name + " Based On a SystemType:" + this.BaseType.Name); this.HasSysBase = true; throw new Exception("不得继承系统类型,脚本类型系统和脚本类型系统是隔离的"); } this.BaseType = null; } bool hasInterfaces = this.type_CLRSharp.HasInterfaces; if (hasInterfaces) { this._Interfaces = new List <ICLRType>(); bool flag4 = true; foreach (TypeReference current in this.type_CLRSharp.Interfaces) { ICLRType type2 = env.GetType(current.FullName); bool flag5 = type2 is ICLRType_System; if (flag5) { Type typeForSystem = (type2 as ICLRType_System).TypeForSystem; bool flag6 = flag4 & env.GetCrossBind(typeForSystem) == null; if (flag6) { bool isInterface = typeForSystem.IsInterface; if (isInterface) { Type[] interfaces = typeForSystem.GetInterfaces(); for (int i = 0; i < interfaces.Length; i++) { Type type3 = interfaces[i]; bool flag7 = env.GetCrossBind(type3) != null; if (flag7) { flag4 = false; break; } } } bool flag8 = flag4; if (flag8) { env.logger.Log_Warning("警告:没有CrossBind的情况下直接继承\nScriptType:" + this.Name + " Based On a SystemInterface:" + type2.Name); } } this.HasSysBase = true; } this._Interfaces.Add(type2); } } } foreach (MethodDefinition current2 in this.type_CLRSharp.Methods) { bool flag9 = current2.Name == ".cctor"; if (flag9) { this.NeedCCtor = true; break; } } }
public void InitToken(ThreadContext context, CodeBody body, object _p) { switch (code) { case CodeEx.Leave: case CodeEx.Leave_S: case CodeEx.Br: case CodeEx.Br_S: case CodeEx.Brtrue: case CodeEx.Brtrue_S: case CodeEx.Brfalse: case CodeEx.Brfalse_S: //比较流程控制 case CodeEx.Beq: case CodeEx.Beq_S: case CodeEx.Bne_Un: case CodeEx.Bne_Un_S: case CodeEx.Bge: case CodeEx.Bge_S: case CodeEx.Bge_Un: case CodeEx.Bge_Un_S: case CodeEx.Bgt: case CodeEx.Bgt_S: case CodeEx.Bgt_Un: case CodeEx.Bgt_Un_S: case CodeEx.Ble: case CodeEx.Ble_S: case CodeEx.Ble_Un: case CodeEx.Ble_Un_S: case CodeEx.Blt: case CodeEx.Blt_S: case CodeEx.Blt_Un: case CodeEx.Blt_Un_S: //this.tokenAddr = ((Mono.Cecil.Cil.Instruction)_p).Offset; this.tokenAddr_Index = body.addr[((Mono.Cecil.Cil.Instruction)_p).Offset]; break; case CodeEx.Isinst: case CodeEx.Constrained: case CodeEx.Box: case CodeEx.Initobj: case CodeEx.Castclass: case CodeEx.Newarr: this.tokenType = context.GetType(_p); //this.tokenUnknown = _p; break; case CodeEx.Ldfld: case CodeEx.Ldflda: case CodeEx.Ldsfld: case CodeEx.Ldsflda: case CodeEx.Stfld: case CodeEx.Stsfld: this.tokenField = context.GetField(_p); //this.tokenUnknown = _p; break; case CodeEx.Call: case CodeEx.Callvirt: case CodeEx.Newobj: case CodeEx.Ldftn: case CodeEx.Ldvirtftn: this.tokenMethod = context.GetMethod(_p); break; case CodeEx.Ldc_I4: this.tokenI32 = (int)_p; break; case CodeEx.Ldc_I4_S: this.tokenI32 = (int)Convert.ToDecimal(_p); break; case CodeEx.Ldc_I4_M1: this.tokenI32 = -1; break; case CodeEx.Ldc_I4_0: this.tokenI32 = 0; break; case CodeEx.Ldc_I4_1: this.tokenI32 = 1; break; case CodeEx.Ldc_I4_2: this.tokenI32 = 2; break; case CodeEx.Ldc_I4_3: this.tokenI32 = 3; break; case CodeEx.Ldc_I4_4: this.tokenI32 = 4; break; case CodeEx.Ldc_I4_5: this.tokenI32 = 5; break; case CodeEx.Ldc_I4_6: this.tokenI32 = 6; break; case CodeEx.Ldc_I4_7: this.tokenI32 = 7; break; case CodeEx.Ldc_I4_8: this.tokenI32 = 8; break; case CodeEx.Ldc_I8: this.tokenI64 = (Int64)_p; break; case CodeEx.Ldc_R4: this.tokenR32 = (float)_p; break; case CodeEx.Ldc_R8: this.tokenR64 = (double)_p; break; case CodeEx.Ldstr: this.tokenStr = _p as string; break; case CodeEx.Ldloca: case CodeEx.Ldloca_S: case CodeEx.Ldloc_S: case CodeEx.Stloc_S: this.tokenI32 = ((VariableDefinition)_p).Index; //this.tokenUnknown = _p; break; case CodeEx.Ldloc: case CodeEx.Stloc: this.tokenI32 = (int)_p; break; case CodeEx.Ldloc_0: this.tokenI32 = 0; break; case CodeEx.Ldloc_1: this.tokenI32 = 1; break; case CodeEx.Ldloc_2: this.tokenI32 = 2; break; case CodeEx.Ldloc_3: this.tokenI32 = 3; break; case CodeEx.Ldarga: case CodeEx.Ldarga_S: case CodeEx.Starg: case CodeEx.Starg_S: this.tokenI32 = (_p as Mono.Cecil.ParameterDefinition).Index; break; case CodeEx.Switch: { Mono.Cecil.Cil.Instruction[] e = _p as Mono.Cecil.Cil.Instruction[]; tokenAddr_Switch = new int[e.Length]; for (int i = 0; i < e.Length; i++) { tokenAddr_Switch[i] = body.addr[(e[i].Offset)]; } } break; case CodeEx.Ldarg: this.tokenI32 = (int)_p; break; case CodeEx.Ldarg_S: this.tokenI32 = (_p as Mono.Cecil.ParameterReference).Index; break; case CodeEx.Volatile: case CodeEx. Ldind_I1: case CodeEx. Ldind_U1: case CodeEx. Ldind_I2: case CodeEx. Ldind_U2: case CodeEx. Ldind_I4: case CodeEx. Ldind_U4: case CodeEx. Ldind_I8: case CodeEx. Ldind_I: case CodeEx. Ldind_R4: case CodeEx. Ldind_R8: case CodeEx. Ldind_Ref: break; default: this.tokenUnknown = _p; break; } }
/// <summary> /// 是否存在实例 /// </summary> /// <param name="type">L#类型</param> /// <returns>bool</returns> public bool hasInstance(ICLRType clrType) { return m_instanceDic.ContainsKey(clrType.FullName); }
public static string[] getEnumItemNames(ICLRType clrType) { List<string> itemNames = new List<string>(clrType.GetFieldNames()); itemNames.RemoveAt(0); return itemNames.ToArray(); }
public SocketListenerVO(ICLRType clrType, SocketListenerDele fun) { this.clrType = clrType; this.fun = fun; }
public void InitToken(ThreadContext context, CodeBody body, object _p) { CodeEx codeEx = this.code; switch (codeEx) { case CodeEx.Ldloc_0: this.tokenI32 = 0; return; case CodeEx.Ldloc_1: this.tokenI32 = 1; return; case CodeEx.Ldloc_2: this.tokenI32 = 2; return; case CodeEx.Ldloc_3: this.tokenI32 = 3; return; case CodeEx.Stloc_0: case CodeEx.Stloc_1: case CodeEx.Stloc_2: case CodeEx.Stloc_3: case CodeEx.Ldnull: case CodeEx.Dup: case CodeEx.Pop: case CodeEx.Jmp: case CodeEx.Calli: case CodeEx.Ret: case CodeEx.Stind_Ref: case CodeEx.Stind_I1: case CodeEx.Stind_I2: case CodeEx.Stind_I4: case CodeEx.Stind_I8: case CodeEx.Stind_R4: case CodeEx.Stind_R8: case CodeEx.Add: case CodeEx.Sub: case CodeEx.Mul: case CodeEx.Div: case CodeEx.Div_Un: case CodeEx.Rem: case CodeEx.Rem_Un: case CodeEx.And: case CodeEx.Or: case CodeEx.Xor: case CodeEx.Shl: case CodeEx.Shr: case CodeEx.Shr_Un: case CodeEx.Neg: case CodeEx.Not: case CodeEx.Conv_I1: case CodeEx.Conv_I2: case CodeEx.Conv_I4: case CodeEx.Conv_I8: case CodeEx.Conv_R4: case CodeEx.Conv_R8: case CodeEx.Conv_U4: case CodeEx.Conv_U8: case CodeEx.Cpobj: case CodeEx.Ldobj: case CodeEx.Conv_R_Un: case CodeEx.Unbox: case CodeEx.Throw: case CodeEx.Stobj: case CodeEx.Conv_Ovf_I1_Un: case CodeEx.Conv_Ovf_I2_Un: case CodeEx.Conv_Ovf_I4_Un: case CodeEx.Conv_Ovf_I8_Un: case CodeEx.Conv_Ovf_U1_Un: case CodeEx.Conv_Ovf_U2_Un: case CodeEx.Conv_Ovf_U4_Un: case CodeEx.Conv_Ovf_U8_Un: case CodeEx.Conv_Ovf_I_Un: case CodeEx.Conv_Ovf_U_Un: goto IL_4AA; case CodeEx.Ldarg_S: this.tokenI32 = (_p as ParameterReference).Index; return; case CodeEx.Ldarga_S: case CodeEx.Starg_S: goto IL_42C; case CodeEx.Ldloc_S: case CodeEx.Ldloca_S: case CodeEx.Stloc_S: goto IL_3D5; case CodeEx.Ldc_I4_M1: this.tokenI32 = -1; return; case CodeEx.Ldc_I4_0: this.tokenI32 = 0; return; case CodeEx.Ldc_I4_1: this.tokenI32 = 1; return; case CodeEx.Ldc_I4_2: this.tokenI32 = 2; return; case CodeEx.Ldc_I4_3: this.tokenI32 = 3; return; case CodeEx.Ldc_I4_4: this.tokenI32 = 4; return; case CodeEx.Ldc_I4_5: this.tokenI32 = 5; return; case CodeEx.Ldc_I4_6: this.tokenI32 = 6; return; case CodeEx.Ldc_I4_7: this.tokenI32 = 7; return; case CodeEx.Ldc_I4_8: this.tokenI32 = 8; return; case CodeEx.Ldc_I4_S: this.tokenI32 = (int)Convert.ToDecimal(_p); return; case CodeEx.Ldc_I4: this.tokenI32 = (int)_p; return; case CodeEx.Ldc_I8: this.tokenI64 = (long)_p; return; case CodeEx.Ldc_R4: this.tokenR32 = (float)_p; return; case CodeEx.Ldc_R8: this.tokenR64 = (double)_p; return; case CodeEx.Call: case CodeEx.Callvirt: case CodeEx.Newobj: goto IL_2E0; case CodeEx.Br_S: case CodeEx.Brfalse_S: case CodeEx.Brtrue_S: case CodeEx.Beq_S: case CodeEx.Bge_S: case CodeEx.Bgt_S: case CodeEx.Ble_S: case CodeEx.Blt_S: case CodeEx.Bne_Un_S: case CodeEx.Bge_Un_S: case CodeEx.Bgt_Un_S: case CodeEx.Ble_Un_S: case CodeEx.Blt_Un_S: case CodeEx.Br: case CodeEx.Brfalse: case CodeEx.Brtrue: case CodeEx.Beq: case CodeEx.Bge: case CodeEx.Bgt: case CodeEx.Ble: case CodeEx.Blt: case CodeEx.Bne_Un: case CodeEx.Bge_Un: case CodeEx.Bgt_Un: case CodeEx.Ble_Un: case CodeEx.Blt_Un: break; case CodeEx.Switch: { Instruction[] array = _p as Instruction[]; this.tokenAddr_Switch = new int[array.Length]; for (int i = 0; i < array.Length; i++) { this.tokenAddr_Switch[i] = body.addr[array[i].Offset]; } return; } case CodeEx.Ldind_I1: case CodeEx.Ldind_U1: case CodeEx.Ldind_I2: case CodeEx.Ldind_U2: case CodeEx.Ldind_I4: case CodeEx.Ldind_U4: case CodeEx.Ldind_I8: case CodeEx.Ldind_I: case CodeEx.Ldind_R4: case CodeEx.Ldind_R8: case CodeEx.Ldind_Ref: goto IL_4A8; case CodeEx.Ldstr: this.tokenStr = (_p as string); return; case CodeEx.Castclass: case CodeEx.Isinst: case CodeEx.Box: case CodeEx.Newarr: goto IL_2BC; case CodeEx.Ldfld: case CodeEx.Ldflda: case CodeEx.Stfld: case CodeEx.Ldsfld: case CodeEx.Ldsflda: case CodeEx.Stsfld: this.tokenField = context.GetField(_p); return; default: switch (codeEx) { case CodeEx.Leave: case CodeEx.Leave_S: break; case CodeEx.Stind_I: case CodeEx.Conv_U: case CodeEx.Arglist: case CodeEx.Ceq: case CodeEx.Cgt: case CodeEx.Cgt_Un: case CodeEx.Clt: case CodeEx.Clt_Un: case CodeEx.Localloc: case CodeEx.Endfilter: case CodeEx.Unaligned: case CodeEx.Tail: goto IL_4AA; case CodeEx.Ldftn: case CodeEx.Ldvirtftn: goto IL_2E0; case CodeEx.Ldarg: this.tokenI32 = (int)_p; return; case CodeEx.Ldarga: case CodeEx.Starg: goto IL_42C; case CodeEx.Ldloc: case CodeEx.Stloc: this.tokenI32 = (int)_p; return; case CodeEx.Ldloca: goto IL_3D5; case CodeEx.Volatile: goto IL_4A8; case CodeEx.Initobj: case CodeEx.Constrained: goto IL_2BC; default: goto IL_4AA; } break; } this.tokenAddr_Index = body.addr[((Instruction)_p).Offset]; return; IL_2BC: this.tokenType = context.GetType(_p); return; IL_2E0: this.tokenMethod = context.GetMethod(_p); return; IL_3D5: this.tokenI32 = ((VariableDefinition)_p).Index; return; IL_42C: this.tokenI32 = (_p as ParameterDefinition).Index; IL_4A8: return; IL_4AA: this.tokenUnknown = _p; }
//============================================================ /// <summary> /// 获取GMonoBehaviour事件的方法 /// </summary> /// <param name="clrType"></param> /// <param name="method"></param> /// <param name="paramTypes"></param> /// <returns></returns> public IMethod getGMBEventMethod(ICLRType clrType, GMBEventMethod method, MethodParamList paramTypes = null) { if (paramTypes == null) { paramTypes = MethodParamList.constEmpty(); } if (clrType == null || clrType.FullName == "Freamwork.GMB") { return null; } Dictionary<string, IMethod> methodDic; if (!dic.ContainsKey(clrType.FullName)) { methodDic = new Dictionary<string, IMethod>(); dic.Add(clrType.FullName, methodDic); } else { methodDic = dic[clrType.FullName]; } string methodName = totalMethodNameList[(int)method]; if (methodDic.ContainsKey(methodName)) { return methodDic[methodName]; } IMethod eventMethod = clrType.GetMethod(methodName, paramTypes); if (eventMethod == null) { Type_Common_CLRSharp type = clrType as Type_Common_CLRSharp; if (type != null) { eventMethod = getGMBEventMethod(type.BaseType, method, paramTypes); } } methodDic[methodName] = eventMethod; return eventMethod; }
/// <summary> /// 实例化L#类 /// </summary> /// <param name="clrType">L#类</param> /// <param name="paramTypes">L#类构造函数的参数类型</param> /// <param name="param">L#类构造函数的参数</param> /// <returns>实例</returns> public object creatCLRInstance(ICLRType clrType, MethodParamList paramTypes = null, object[] param = null) { return Invoke(clrType, CLRSharpConstant.METHOD_CTOR, null, paramTypes, param); }
//********************************* 单例管理 ************************************* /// <summary> /// 获取MVCObject实例,如果实例不存在将会创建 /// </summary> /// <param name="type">L#类型</param> /// <returns>IMVCObject</returns> public object getInstance(ICLRType clrType) { string fullName = clrType.FullName; if (!m_instanceDic.ContainsKey(fullName)) { List<ICLRType> list = CLRSharpManager.instance.getInterfaces(clrType as Type_Common_CLRSharp); if (!list.Contains(typeof(IMVCObject) as ICLRType)) { throw new Exception(fullName + "并非IMVCObject的实现者,无法通过MVCCharge来管理"); } object mvcObject = CLRSharpManager.instance.creatCLRInstance(clrType); m_instanceDic.Add(fullName, mvcObject); } return m_instanceDic[fullName]; }
/// <summary> /// 获取方法,可以获取继承的方法 /// </summary> /// <param name="clrType">类型</param> /// <param name="funName">方法名</param> /// <param name="paramTypes">参数类型</param> /// <returns></returns> public IMethod GetMethod(ICLRType clrType, string funName, MethodParamList paramTypes = null) { if (paramTypes == null) { paramTypes = MethodParamList.constEmpty(); } IMethod fun = clrType.GetMethod(funName, paramTypes); if (fun == null) { Type_Common_CLRSharp subType = clrType as Type_Common_CLRSharp; if (subType != null && subType.BaseType != null) { fun = GetMethod(subType.BaseType, funName, paramTypes); } } return fun; }
//********************************* 发送命令 ************************************* /// <summary> /// 发送命令 /// </summary> /// <param name="type">L#类型</param> /// <param name="param">命令携带的参数</param> public void sendCommand(ICLRType clrType, object param) { CLRSharpManager mana = CLRSharpManager.instance; object command = mana.creatCLRInstance(clrType); MethodParamList paramTypes = mana.getParamTypeList(typeof(object)); object[] paramList = new object[] { param }; mana.Invoke(clrType, "execute", command, paramTypes, paramList); }
/// <summary> /// 获取参数类型列表 /// </summary> /// <param name="types">类型</param> /// <returns></returns> public MethodParamList getParamTypeList(params Type[] types) { int len = types.Length; ICLRType[] list = new ICLRType[len]; for (int i = 0; i < len; i++ ) { list[i] = env.GetType(types[i]); } return MethodParamList.Make(list); }
public IMethod GetMethod(object token) { IMethod result; try { IMethod method = null; bool flag = this.methodCache.TryGetValue(token.GetHashCode(), out method); if (flag) { result = method; } else { MethodParamList methodParamList = null; bool flag2 = token is MethodReference; string name; string text; MethodParamList types; if (flag2) { MethodReference methodReference = token as MethodReference; ModuleDefinition module = methodReference.Module; name = methodReference.Name; text = methodReference.DeclaringType.FullName; types = new MethodParamList(this.environment, methodReference); bool isGenericInstance = methodReference.IsGenericInstance; if (isGenericInstance) { GenericInstanceMethod method2 = methodReference as GenericInstanceMethod; methodParamList = new MethodParamList(this.environment, method2); } } else { bool flag3 = token is MethodDefinition; if (!flag3) { throw new NotImplementedException(); } MethodDefinition methodDefinition = token as MethodDefinition; ModuleDefinition module = methodDefinition.Module; name = methodDefinition.Name; text = methodDefinition.DeclaringType.FullName; types = new MethodParamList(this.environment, methodDefinition); bool isGenericInstance2 = methodDefinition.IsGenericInstance; if (isGenericInstance2) { throw new NotImplementedException(); } } ICLRType type = this.GetType(text); bool flag4 = type == null; if (flag4) { text = text.Replace("0...", ""); type = this.GetType(text); } bool flag5 = type == null; if (flag5) { throw new Exception("type can't find:" + text); } bool flag6 = methodParamList != null; IMethod method3; if (flag6) { method3 = type.GetMethodT(name, methodParamList, types); } else { method3 = type.GetMethod(name, types); } this.methodCache[token.GetHashCode()] = method3; result = method3; } } catch (Exception innerException) { throw new Exception("Error GetMethod==<这意味着这个函数无法被L#找到>" + token, innerException); } return(result); }
/// <summary> /// 调用L#的函数 /// </summary> /// <param name="clrType">L#类</param> /// <param name="methodName">L#方法名称</param> /// <param name="methodName">L#类的实例,如果为null,则调用的是静态函数</param> /// <param name="paramTypes">参数类型数组</param> /// <param name="param">参数数组</param> /// <returns>返回值</returns> public object Invoke(ICLRType clrType, string methodName, object inst = null, MethodParamList paramTypes = null, object[] param = null) { if (paramTypes == null) { paramTypes = MethodParamList.constEmpty(); } IMethod method = GetMethod(clrType, methodName, paramTypes); return method.Invoke(context, inst, param); }
public IMethod GetMethodOverloaded(string funcname, MethodParamList types) { MethodDefinition methodDefinition = null; List <int> list = null; bool hasMethods = this.type_CLRSharp.HasMethods; IMethod result; if (hasMethods) { foreach (MethodDefinition current in this.type_CLRSharp.Methods) { bool flag = current.Name != funcname; if (!flag) { bool flag2 = (types == null) ? (!current.HasParameters) : (current.Parameters.Count == types.Count); if (flag2) { bool flag3 = true; List <int> list2 = new List <int>(); for (int i = 0; i < ((types == null) ? 0 : types.Count); i++) { ICLRType type = this.env.GetType(current.Parameters[i].ParameterType.FullName); bool flag4 = type.IsEnum(); if (flag4) { bool flag5 = type.TypeForSystem != types[i].TypeForSystem; if (flag5) { flag3 = false; break; } } else { bool flag6 = !type.TypeForSystem.IsAssignableFrom(types[i].TypeForSystem); if (flag6) { flag3 = false; break; } list2.Add(this.GetInheritanceDistance(type.TypeForSystem, types[i].TypeForSystem)); } } bool flag7 = flag3; if (flag7) { bool flag8 = list == null; if (flag8) { methodDefinition = current; list = list2; } else { for (int j = 0; j < list2.Count; j++) { bool flag9 = list2[j] < list[j]; if (flag9) { methodDefinition = current; list = list2; } } } } } } } bool flag10 = methodDefinition == null; if (flag10) { result = null; } else { result = new Method_Common_CLRSharp(this, methodDefinition); } } else { result = null; } return(result); }
/// <summary> /// 初始化数据 /// </summary> /// <param name="voCLRType">vo的L#类型</param> /// <param name="name">数据表名称,不带后缀</param> /// <param name="order">数据是否有顺序性</param> protected virtual void initDBModel(ICLRType voCLRType = null, string sheet = "", bool order = false) { object dbvoCLRType = typeof(DBVO); if (!CLRSharpManager.instance.isExtend(voCLRType as Type_Common_CLRSharp, dbvoCLRType as Type_Common_CLRSharp)) { throw new Exception(this.GetType().FullName + "初始化时VO的类型并非是DBVO的子类"); } this.voCLRType = voCLRType; this.order = order; xmlNode = DBXMLManager.instance.extractXmlNode(sheet); count = xmlNode.ChildNodes.Count; dataDic = new Dictionary<int, object>(); if (order) { ids = new int[count]; } }
////valuetype // public NumberType TypeOnDef; // public NumberOnStack TypeOnStack; // public IBox box; //public static IBox Make(ICLRType type) //{ // return Make(type.TypeForSystem); //} public static VBox MakeVBox(ICLRType type) { return(MakeVBox(type.TypeForSystem)); }
////valuetype // public NumberType TypeOnDef; // public NumberOnStack TypeOnStack; // public IBox box; //public static IBox Make(ICLRType type) //{ // return Make(type.TypeForSystem); //} public static VBox MakeVBox(ICLRType type) { if (type == null) return null; return MakeVBox(type.TypeForSystem); }
public void InitToken(ThreadContext context, CodeBody body, object _p) { switch (code) { case CodeEx.Leave: case CodeEx.Leave_S: case CodeEx.Br: case CodeEx.Br_S: case CodeEx.Brtrue: case CodeEx.Brtrue_S: case CodeEx.Brfalse: case CodeEx.Brfalse_S: //比较流程控制 case CodeEx.Beq: case CodeEx.Beq_S: case CodeEx.Bne_Un: case CodeEx.Bne_Un_S: case CodeEx.Bge: case CodeEx.Bge_S: case CodeEx.Bge_Un: case CodeEx.Bge_Un_S: case CodeEx.Bgt: case CodeEx.Bgt_S: case CodeEx.Bgt_Un: case CodeEx.Bgt_Un_S: case CodeEx.Ble: case CodeEx.Ble_S: case CodeEx.Ble_Un: case CodeEx.Ble_Un_S: case CodeEx.Blt: case CodeEx.Blt_S: case CodeEx.Blt_Un: case CodeEx.Blt_Un_S: //this.tokenAddr = ((Mono.Cecil.Cil.Instruction)_p).Offset; this.tokenAddr_Index = body.addr[((Mono.Cecil.Cil.Instruction)_p).Offset]; break; case CodeEx.Isinst: case CodeEx.Constrained: case CodeEx.Box: case CodeEx.Initobj: case CodeEx.Castclass: case CodeEx.Newarr: this.tokenType = context.GetType(_p); //this.tokenUnknown = _p; break; case CodeEx.Ldfld: case CodeEx.Ldflda: case CodeEx.Ldsfld: case CodeEx.Ldsflda: case CodeEx.Stfld: case CodeEx.Stsfld: this.tokenField = context.GetField(_p); //this.tokenUnknown = _p; break; case CodeEx.Call: case CodeEx.Callvirt: case CodeEx.Newobj: case CodeEx.Ldftn: case CodeEx.Ldvirtftn: this.tokenMethod = context.GetMethod(_p); break; case CodeEx.Ldc_I4: this.tokenI32 = (int)_p; break; case CodeEx.Ldc_I4_S: this.tokenI32 = (int)Convert.ToDecimal(_p); break; case CodeEx.Ldc_I4_M1: this.tokenI32 = -1; break; case CodeEx.Ldc_I4_0: this.tokenI32 = 0; break; case CodeEx.Ldc_I4_1: this.tokenI32 = 1; break; case CodeEx.Ldc_I4_2: this.tokenI32 = 2; break; case CodeEx.Ldc_I4_3: this.tokenI32 = 3; break; case CodeEx.Ldc_I4_4: this.tokenI32 = 4; break; case CodeEx.Ldc_I4_5: this.tokenI32 = 5; break; case CodeEx.Ldc_I4_6: this.tokenI32 = 6; break; case CodeEx.Ldc_I4_7: this.tokenI32 = 7; break; case CodeEx.Ldc_I4_8: this.tokenI32 = 8; break; case CodeEx.Ldc_I8: this.tokenI64 = (Int64)_p; break; case CodeEx.Ldc_R4: this.tokenR32 = (float)_p; break; case CodeEx.Ldc_R8: this.tokenR64 = (double)_p; break; case CodeEx.Ldstr: this.tokenStr = _p as string; break; case CodeEx.Ldloca: case CodeEx.Ldloca_S: case CodeEx.Ldloc_S: case CodeEx.Stloc_S: this.tokenI32 = ((VariableDefinition)_p).Index; //this.tokenUnknown = _p; break; case CodeEx.Ldloc: case CodeEx.Stloc: this.tokenI32 = (int)_p; break; case CodeEx.Ldloc_0: this.tokenI32 = 0; break; case CodeEx.Ldloc_1: this.tokenI32 = 1; break; case CodeEx.Ldloc_2: this.tokenI32 = 2; break; case CodeEx.Ldloc_3: this.tokenI32 = 3; break; case CodeEx.Ldarga: case CodeEx.Ldarga_S: case CodeEx.Starg: case CodeEx.Starg_S: this.tokenI32 = (_p as Mono.Cecil.ParameterDefinition).Index; break; case CodeEx.Switch: { Mono.Cecil.Cil.Instruction[] e = _p as Mono.Cecil.Cil.Instruction[]; tokenAddr_Switch = new int[e.Length]; for (int i = 0; i < e.Length; i++) { tokenAddr_Switch[i] = body.addr[(e[i].Offset)]; } } break; case CodeEx.Ldarg: this.tokenI32 = (int)_p; break; case CodeEx.Ldarg_S: this.tokenI32 = (_p as Mono.Cecil.ParameterReference).Index; break; case CodeEx.Volatile: break; default: this.tokenUnknown = _p; break; } }
//得到类型的时候应该得到模块内Type或者真实Type //一个统一的Type,然后根据具体情况调用两边 public ICLRType GetType(string fullname) { try { ICLRType type = null; bool b = mapType.TryGetValue(fullname, out type); if (!b) { List <ICLRType> subTypes = new List <ICLRType>(); if (fullname.Contains("<>") || fullname.Contains("/"))//匿名类型 { string[] subts = fullname.Split('/'); ICLRType ft = GetType(subts[0]); if (ft is ICLRType_Sharp) { for (int i = 1; i < subts.Length; i++) { ft = ft.GetNestType(this, subts[i]); } return(ft); } } string fullnameT = fullname;//.Replace('/', '+'); if (fullnameT.Contains("<")) { string outname = ""; int depth = 0; int lastsplitpos = 0; for (int i = 0; i < fullname.Length; i++) { string checkname = null; if (fullname[i] == '/') { } else if (fullname[i] == '<') { if (i != 0) { depth++; } if (depth == 1)// { lastsplitpos = i; outname += "["; continue; } } else if (fullname[i] == '>') { if (depth == 1) { checkname = fullnameT.Substring(lastsplitpos + 1, i - lastsplitpos - 1); var subtype = GetType(checkname); subTypes.Add(subtype); if (!subtype.IsEnum() && subtype is ICLRType_Sharp) { subtype = GetType(typeof(CLRSharp_Instance)); } outname += "[" + subtype.FullNameWithAssembly + "]"; lastsplitpos = i; } //if(depth>0) depth--; if (depth == 0) { outname += "]"; continue; } else if (depth < 0) { depth = 0; } } else if (fullname[i] == ',') { if (depth == 1) { checkname = fullnameT.Substring(lastsplitpos + 1, i - lastsplitpos - 1); var subtype = GetType(checkname); subTypes.Add(subtype); if (!subtype.IsEnum() && subtype is ICLRType_Sharp) { subtype = GetType(typeof(CLRSharp_Instance)); } outname += "[" + subtype.FullNameWithAssembly + "],"; lastsplitpos = i; } } if (depth == 0) { outname += fullnameT[i]; } } fullnameT = outname; // fullnameT = fullnameT.Replace('<', '['); //fullnameT = fullnameT.Replace('>', ']'); } fullnameT = fullnameT.Replace('/', '+'); System.Type t = System.Type.GetType(fullnameT); if (t == null) { if (assemblylist != null) { foreach (var i in assemblylist) { t = i.GetType(fullnameT); if (t != null) { break; } } } if (t == null) { foreach (var rm in moduleref) { t = System.Type.GetType(fullnameT + "," + rm); if (t != null) { fullnameT = fullnameT + "," + rm; break; } } } } if (t != null) { //之所以做这么扭曲的设计,是因为Unity的Type.Fullname 实现错误,导致在Unity环境Type.FullName不一致 if (t.FullName.Contains("CLRSharp.CLRSharp_Instance") == false) { b = mapType.TryGetValue(t.FullName, out type); if (b) { //mapType[fullname] = type; return(type); } type = new Type_Common_System(this, t, subTypes.ToArray()); mapType[t.FullName] = type; return(type); } else { } type = new Type_Common_System(this, t, subTypes.ToArray()); mapType[fullname] = type; //mapType[t.FullName] = type; } } return(type); } catch (Exception err) { throw new Exception("Error in getType:" + fullname, err); } }
/// <summary> /// 删除存储的实例 /// </summary> /// <param name="type">L#类型</param> /// <returns>bool</returns> public bool delInstance(ICLRType clrType) { if (m_instanceDic.ContainsKey(clrType.FullName)) { CLRSharp_Instance mvcObject = m_instanceDic[clrType.FullName] as CLRSharp_Instance; m_instanceDic.Remove(clrType.FullName); if (!(bool)(mvcObject.Fields["disposed"])) { CLRSharpManager.instance.Invoke(clrType, "dispose", mvcObject); } return true; } return false; }
/// <summary> /// 添加回调侦听 /// </summary> /// <param name="protocol">协议号</param> /// <param name="fun">回调方法</param> /// <param name="clrType">数据的CLR类型</param> protected void addListener(int protocol, SocketListenerDele fun, ICLRType clrType) { protocolList.Add(protocol); SocketManager.instance.addListener(protocol, fun, clrType); }
////valuetype // public NumberType TypeOnDef; // public NumberOnStack TypeOnStack; // public IBox box; //public static IBox Make(ICLRType type) //{ // return Make(type.TypeForSystem); //} public static VBox MakeVBox(ICLRType type) { return MakeVBox(type.TypeForSystem); }