Beispiel #1
0
    private TableData GetData(string tableName, TextAsset textAsset)
    {
        TableData tableData = new TableData();

        string[] rowData = textAsset.text.Split(new string[] { "\r\n" }, StringSplitOptions.None);  // 拆分行
        if (rowData.Length < 3)
        {
            return(null);
        }

        List <PropertyInfo> propertyInfoList = GetPropertyInfoList(tableName, rowData[1]);

        for (int i = 3; i < rowData.Length; ++i)
        {
            // 实例化一个 T 类对象
            object      row     = TableDefine.GetTableType(tableName);
            System.Type t       = row.GetType();
            string[]    cloData = rowData[i].Split('`'); // 拆分行
            if (cloData.Length < propertyInfoList.Count || (cloData.Length > 0 && string.IsNullOrEmpty(cloData[0])))
            {
                continue;
            }
            PropertyInfo property;
            for (int j = 0; j < cloData.Length; ++j)
            {
                if (propertyInfoList.Count <= j)
                {
                    UnityEngine.Debug.LogError("属性列不对 " + tableName + "   列:" + j);
                    break;
                }

                property = propertyInfoList[j];
                try
                {
                    property.SetValue(row, Convert.ChangeType(cloData[j], property.PropertyType), null); // 给属性赋值
                }
                catch
                {
                }
            }

            object keyID = -1;  // 主键
            if (propertyInfoList.Count > 0)
            {
                keyID = propertyInfoList[0].GetValue(row, null);  // 获取主键ID
            }
            tableData.AddRowData(keyID, row);
        }

        return(tableData);
    }