예제 #1
0
    static string GetGenericNameSpace(Type t, out string libName)
    {
        Type[] gArgs    = t.GetGenericArguments();
        string typeName = t.FullName;
        int    count    = gArgs.Length;
        int    pos      = typeName.IndexOf("[");

        typeName = typeName.Substring(0, pos);

        string str    = null;
        string name   = null;
        int    offset = 0;

        pos = typeName.IndexOf("+");

        while (pos > 0)
        {
            str      = typeName.Substring(0, pos);
            typeName = typeName.Substring(pos + 1);
            pos      = str.IndexOf('`');

            if (pos > 0)
            {
                count   = (int)(str[pos + 1] - '0');
                str     = str.Substring(0, pos);
                str    += "<" + string.Join(",", LuaMisc.GetGenericName(gArgs, offset, count)) + ">";
                offset += count;
            }

            name = CombineTypeStr(name, str);
            pos  = typeName.IndexOf("+");
        }

        string space = name;

        str = typeName;

        if (offset < gArgs.Length)
        {
            pos   = str.IndexOf('`');
            count = (int)(str[pos + 1] - '0');
            str   = str.Substring(0, pos);
            str  += "<" + string.Join(",", LuaMisc.GetGenericName(gArgs, offset, count)) + ">";
        }

        libName = str;

        if (string.IsNullOrEmpty(space))
        {
            space = t.Namespace;

            if (space != null)
            {
                libName = str.Substring(space.Length + 1);
            }
        }

        return(space);
    }