public ICLRType GetType(string fullname) { ICLRType result; try { ICLRType iCLRType = null; bool flag = this.mapType.TryGetValue(fullname, out iCLRType); bool flag2 = !flag; if (flag2) { List <ICLRType> list = new List <ICLRType>(); bool flag3 = fullname.Contains("<>") || fullname.Contains("/"); if (flag3) { string[] array = fullname.Split(new char[] { '/' }); ICLRType iCLRType2 = this.GetType(array[0]); bool flag4 = iCLRType2 is ICLRType_Sharp; if (flag4) { for (int i = 1; i < array.Length; i++) { iCLRType2 = iCLRType2.GetNestType(this, array[i]); } result = iCLRType2; return(result); } } string text = fullname; bool flag5 = text.Contains("<"); if (flag5) { string text2 = ""; int num = 0; int num2 = 0; int j = 0; while (j < fullname.Length) { bool flag6 = fullname[j] == '/'; if (flag6) { goto IL_2AF; } bool flag7 = fullname[j] == '<'; if (flag7) { bool flag8 = j != 0; if (flag8) { num++; } bool flag9 = num == 1; if (!flag9) { goto IL_2AF; } num2 = j; text2 += "["; } else { bool flag10 = fullname[j] == '>'; if (flag10) { bool flag11 = num == 1; if (flag11) { string fullname2 = text.Substring(num2 + 1, j - num2 - 1); ICLRType type = this.GetType(fullname2); list.Add(type); bool flag12 = !type.IsEnum() && type is ICLRType_Sharp; if (flag12) { type = this.GetType(typeof(CLRSharp_Instance)); } text2 = text2 + "[" + type.FullNameWithAssembly + "]"; num2 = j; } num--; bool flag13 = num == 0; if (!flag13) { bool flag14 = num < 0; if (flag14) { num = 0; } goto IL_2AF; } text2 += "]"; } else { bool flag15 = fullname[j] == ','; if (flag15) { bool flag16 = num == 1; if (flag16) { string fullname2 = text.Substring(num2 + 1, j - num2 - 1); ICLRType type2 = this.GetType(fullname2); list.Add(type2); bool flag17 = !type2.IsEnum() && type2 is ICLRType_Sharp; if (flag17) { type2 = this.GetType(typeof(CLRSharp_Instance)); } text2 = text2 + "[" + type2.FullNameWithAssembly + "],"; num2 = j; } goto IL_2AF; } goto IL_2AF; } } IL_2DE: j++; continue; IL_2AF: bool flag18 = num == 0; if (flag18) { text2 += text[j].ToString(); } goto IL_2DE; } text = text2; } text = text.Replace('/', '+'); Type type3 = Type.GetType(text); bool flag19 = type3 == null; if (flag19) { bool flag20 = this.assemblylist != null; if (flag20) { foreach (Assembly current in this.assemblylist) { type3 = current.GetType(text); bool flag21 = type3 != null; if (flag21) { break; } } } bool flag22 = type3 == null; if (flag22) { foreach (string current2 in this.moduleref) { type3 = Type.GetType(text + "," + current2); bool flag23 = type3 != null; if (flag23) { text = text + "," + current2; break; } } } } bool flag24 = type3 != null; if (flag24) { bool flag25 = !type3.FullName.Contains("CLRSharp.CLRSharp_Instance"); if (flag25) { flag = this.mapType.TryGetValue(type3.FullName, out iCLRType); bool flag26 = flag; if (flag26) { result = iCLRType; return(result); } iCLRType = new Type_Common_System(this, type3, list.ToArray()); this.mapType[type3.FullName] = iCLRType; result = iCLRType; return(result); } else { iCLRType = new Type_Common_System(this, type3, list.ToArray()); this.mapType[fullname] = iCLRType; } } } result = iCLRType; } catch (Exception innerException) { throw new Exception("Error in getType:" + fullname, innerException); } return(result); }
//得到类型的时候应该得到模块内Type或者真实Type //一个统一的Type,然后根据具体情况调用两边 public ICLRType GetType(string fullname) { 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 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 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) { type = new Type_Common_System(this, t, subTypes.ToArray()); } mapType[fullname] = type; } return(type); }
//得到类型的时候应该得到模块内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); if (subtype == null) { continue; } 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); if (checkname.StartsWith("System.Action`")) { checkname = checkname.Substring(0, 15) + "<" + checkname.Substring(16, checkname.Length - 17) + ">"; } else if (checkname.StartsWith("System.Func`")) { checkname = checkname.Substring(0, 13) + "<" + checkname.Substring(14, checkname.Length - 15) + ">"; } 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) { { var __list4 = assemblylist; var __listCount4 = __list4.Count; for (int __i4 = 0; __i4 < __listCount4; ++__i4) { var i = __list4[__i4]; { t = i.GetType(fullnameT); if (t != null) { break; } } } } } if (t == null) { { var __list5 = moduleref; var __listCount5 = __list5.Count; for (int __i5 = 0; __i5 < __listCount5; ++__i5) { var rm = __list5[__i5]; { 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); } }