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

        if (typeName.Contains("[]@"))
        {
            splitChar = typeName.Split('@')[1];
        }
        int  dimension   = ConfigTools.GetGenericDimension(fieldType);
        Type elementType = ConfigTools.GetGenericElementType(fieldType);
        Type d1T         = elementType.MakeArrayType();

        if (dimension == 3)
        {
            Type wrapD2T = fieldType.GetGenericArguments()[0];
            Type wrapD1T = wrapD2T.GetGenericArguments()[0];

            Type d2T = wrapD1T.MakeArrayType();

            string[] line        = data.Split('`');
            Array    arrayD3     = Array.CreateInstance(d2T, line.Length);
            object   wrapArrayD3 = Activator.CreateInstance(fieldType, arrayD3);
            for (int i = 0; i < line.Length; i++)
            {
                string[] p2          = line[i].Split('|');
                Array    arrayD2     = Array.CreateInstance(d1T, p2.Length);
                object   wrapArrayD2 = Activator.CreateInstance(wrapD2T, arrayD2);

                for (int j = 0; j < p2.Length; j++)
                {
                    object wrapArrayD1 = Activator.CreateInstance(wrapD1T, _parseArray(d1T, p2[j], splitChar));
                    arrayD2.SetValue(wrapArrayD1, j);
                }
                arrayD3.SetValue(wrapArrayD2, i);
            }
            return(wrapArrayD3);
        }
        if (dimension == 2)
        {
            Type wrapD1T = fieldType.GetGenericArguments()[0];

            string[] line        = data.Split('|');
            Array    arrayD2     = Array.CreateInstance(wrapD1T, line.Length);
            object   wrapArrayD2 = Activator.CreateInstance(fieldType, arrayD2);
            for (int i = 0; i < line.Length; i++)
            {
                object wrapArrayD1 = Activator.CreateInstance(wrapD1T, _parseArray(d1T, line[i], splitChar));
                arrayD2.SetValue(wrapArrayD1, i);
            }
            return(wrapArrayD2);
        }
        if (dimension == 1)
        {
            object wrapArrayD1 = Activator.CreateInstance(fieldType, _parseArray(d1T, data, splitChar));
            return(wrapArrayD1);
        }
        return(null);
    }