Beispiel #1
0
    private static object _parseArrayConfigField(string typeName, string fieldName, string data, Type fieldType)
    {
        //重载分隔符
        string splitChar = "+";

        if (typeName.Contains("[]@"))
        {
            splitChar = typeName.Split('@')[1];
        }
        int dimension = ConfigTools.GetArrayDimension(fieldType);

        if (dimension == 3)
        {
            string[] line       = data.Split('`');
            Array    arrConfig2 = Array.CreateInstance(fieldType.GetElementType(), line.Length);
            for (int i = 0; i < line.Length; i++)
            {
                string[] p2       = line[i].Split('|');
                Array    tempElem = Array.CreateInstance(fieldType.GetElementType().GetElementType(), p2.Length);

                for (int j = 0; j < p2.Length; j++)
                {
                    tempElem.SetValue(
                        _parseArray(fieldType.GetElementType().GetElementType(), p2[j], splitChar), j);
                }
                arrConfig2.SetValue(tempElem, i);
            }
            return(arrConfig2);
        }
        //字符串数据转换为指定类型数组数据
        if (dimension == 2)
        {
            string[] line       = data.Split('|');
            Array    arrConfig2 = Array.CreateInstance(fieldType.GetElementType(), line.Length);
            for (int i = 0; i < line.Length; i++)
            {
                arrConfig2.SetValue(_parseArray(fieldType.GetElementType(), line[i], splitChar), i);
            }
            return(arrConfig2);
        }
        if (dimension == 1)
        {
            return(_parseArray(fieldType, data, splitChar));
        }
        return(null);
    }
Beispiel #2
0
    //字段类型名转为配置表字段类型名
    private string RuntimeTypeChangeToTypeName(Type t)
    {
        if (t.IsArray || t.IsGenericType)
        {
            if ((t.IsGenericType && t.Name.StartsWith("ReadonlyArray")) || t.IsArray)
            {
                string suff      = "";
                Type   ementType = t;
                int    d         = t.IsArray ? ConfigTools.GetArrayDimension(t) : ConfigTools.GetGenericDimension(t);
                for (int i = 0; i < d; i++)
                {
                    suff     += "[]";
                    ementType = t.IsArray ? ementType.GetElementType() : ementType.GetGenericArguments()[0];
                }

                return(BaseTypeNameChange(ementType, null, suff));
            }
            return(null);
        }
        return(BaseTypeNameChange(t, null, ""));
    }