Inheritance: ICLRType_System
Beispiel #1
0
        //得到类型的时候应该得到模块内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);
            }
        }
Beispiel #2
0
 public ICLRType GetType(System.Type systemType)
 {
     ICLRType type = null;
     bool b = mapType.TryGetValue(systemType.FullName, out type);
     if (!b)
     {
         type = new Type_Common_System(this, systemType, null);
         mapType[systemType.FullName] = type;
     }
     return type;
 }