示例#1
0
    public void PaseArray1()
    {
        {
            string arrayStringContent = "mm#123,haha|papa,haha|ko#888";
            char[] arraySplitFormat   = new char[] { ',', '#' };

            Array array = ParseTool.String2Array(FieldType.StringArray, arrayStringContent, arraySplitFormat);
            Debug.Assert(array != null);
            Debug.Log(JsonUtils.ToJson(array));

            string res = ParseTool.ArrayObject2String(array, arraySplitFormat);
            Debug.Log(res);
            Debug.Assert(res == arrayStringContent);
        }
        {
            string arrayStringContent = "NULl";
            char[] arraySplitFormat   = new char[] { ',', '#' };

            Array array = ParseTool.String2Array(FieldType.StringArray, arrayStringContent, arraySplitFormat);
            Debug.Assert(array == null);
            Debug.Log(JsonUtils.ToJson(array));

            string res = ParseTool.ArrayObject2String(array, arraySplitFormat);
            Debug.Log(res);
            Debug.Assert(res == arrayStringContent.ToLower());
        }
    }
示例#2
0
    public void PaseArray2()
    {
        string arrayStringContent = "haha|papa|ko#888";


        Array array = ParseTool.String2Array(FieldType.StringArray, arrayStringContent, new char[] { });

        Debug.Assert(array != null);
        Debug.Log(JsonUtils.ToJson(array));
    }
示例#3
0
    public Array GetArray(string key)
    {
        try
        {
            if (this.ContainsKey(key))
            {
                return(ParseTool.String2Array(data.GetFieldType(key), this[key], data.GetArraySplitFormat(key)));
            }

            else if (data.m_defaultValue.ContainsKey(key))
            {
                return(ParseTool.String2Array(data.GetFieldType(key), data.m_defaultValue[key], data.GetArraySplitFormat(key)));
            }
        }
        catch (Exception e)
        {
            throw new Exception("SingleData GetStringArray2 Error TableName is :->" + data.m_tableName + "<- key->" + key + "<-  singleDataName : ->" + m_SingleDataKey + "<- \n" + e.ToString());
        }

        throw new Exception("Don't Exist Value or DefaultValue by ->" + key + "<- TableName is : ->" + data.m_tableName + "<- singleDataName : ->" + m_SingleDataKey + "<-");// throw
    }
    /// <summary>
    /// 原始表格字符串类型转换为具体的数据
    /// </summary>
    /// <param name="v"></param>
    /// <param name="fieldValueType"></param>
    /// <param name="enumType"></param>
    /// <returns></returns>
    public static object TableString2ObjectValue(string v, FieldType fieldValueType, string enumType, List <char> m_ArraySplitFormat)
    {
        object t = null;

        switch (fieldValueType)
        {
        case FieldType.String:
            t = v;
            break;

        case FieldType.Bool:
            t = bool.Parse(v);
            break;

        case FieldType.Int:
            t = int.Parse(v);
            break;

        case FieldType.Float:
            t = float.Parse(v);
            break;

        case FieldType.Vector2:
            t = ParseTool.String2Vector2(v);
            break;

        case FieldType.Vector3:
            t = ParseTool.String2Vector3(v);
            break;

        case FieldType.Color:
            t = ParseTool.String2Color(v);
            break;

        case FieldType.Enum:
            Type type = ConfigFieldValueType2Type(fieldValueType, enumType, m_ArraySplitFormat);
            try
            {
                t = Enum.Parse(type, v);
            }
            catch (Exception e)
            {
                t = Enum.GetValues(type).GetValue(0);
                // Debug.LogError("fieldValueType:" + fieldValueType + " enumType:" + enumType + " type:" + type + " v:" + v + "\n"+e);
                throw e;
            }

            break;

        case FieldType.StringArray:

        //t = ParseTool.String2StringArray(v);
        //break;
        case FieldType.IntArray:
        //t = ParseTool.String2IntArray(v);
        //break;
        case FieldType.FloatArray:
        //t = ParseTool.String2FloatArray(v);
        //break;
        case FieldType.BoolArray:
        //t = ParseTool.String2BoolArray(v);
        //break;
        case FieldType.Vector2Array:
        //t = ParseTool.String2Vector2(v);
        //break;
        case FieldType.Vector3Array:
            //t = ParseTool.String2Vector3Array(v);
            t = ParseTool.String2Array(fieldValueType, v, m_ArraySplitFormat.ToArray());
            break;

        default:

            break;
        }

        return(t);
    }