Ejemplo n.º 1
0
        public void AddLine(TableConfigOtherInfo info)
        {
            List <ConfigRowData> data = new List <ConfigRowData>();

            foreach (var item in info.fieldInfoDic.Values)
            {
                ConfigRowData d = new ConfigRowData();
                d.fieldName = item.fieldName;
                d.value     = item.defultValue;
                data.Add(d);
            }

            configRowDataList.Add(data);
        }
Ejemplo n.º 2
0
        private static List <TableConfigBase> ChangeToClassData(Type type, string[][] configDatas)
        {
            TableConfigOtherInfo tableConfigOtherInfo = null;

            if (!TableConfigBase.tableConfigOtherInfo.ContainsKey(type.Name))
            {
                tableConfigOtherInfo = new TableConfigOtherInfo();
                TableConfigBase.tableConfigOtherInfo.Add(type.Name, tableConfigOtherInfo);
            }
            else
            {
                tableConfigOtherInfo = TableConfigBase.tableConfigOtherInfo[type.Name];
            }

            List <TableConfigBase> list = new List <TableConfigBase>();
            string configDescription    = configDatas[0][0];

            tableConfigOtherInfo.configDescription = configDescription;
            for (int j = 0; j < configDatas[4].Length; j++)
            {
                string    fieldName = configDatas[3][j];
                FieldInfo f         = type.GetField(fieldName);
                if (f != null)
                {
                    string typeName           = configDatas[1][j];
                    object defaultData        = GetValue(typeName, configDatas[4][j]);
                    TableConfigFieldInfo info = new TableConfigFieldInfo();
                    info.fieldName      = fieldName;
                    info.defultValue    = defaultData;
                    info.fieldValueType = TableConfigTool.Type2ConfigFieldValueType(info.defultValue.GetType());
                    info.description    = configDatas[2][j];
                    tableConfigOtherInfo.fieldInfoDic.Add(fieldName, info);
                }
            }
            for (int i = 5; i < configDatas.Length; i++)
            {
                TableConfigBase instance = Activator.CreateInstance(type) as TableConfigBase;

                if (instance == null)
                {
                    Debug.LogError("Config Change fail. Name : " + type);
                    break;
                }
                for (int j = 0; j < configDatas[i].Length; j++)
                {
                    string    fieldName = configDatas[3][j];
                    FieldInfo f         = type.GetField(fieldName);
                    if (f != null)
                    {
                        string valueStr    = configDatas[i][j];
                        string typeName    = configDatas[1][j];
                        object value       = null;
                        object defaultData = tableConfigOtherInfo.fieldInfoDic[fieldName].defultValue;
                        if (string.IsNullOrEmpty(valueStr))
                        {
                            value = defaultData;
                        }
                        else
                        {
                            value = GetValue(typeName, valueStr);
                        }

                        f.SetValue(instance, value);
                    }
                }
                list.Add(instance);
            }
            return(list);
        }
Ejemplo n.º 3
0
        public static string ConfigInfo2TableText(TableConfigOtherInfo info, ConfigFileContents configData)
        {
            if (string.IsNullOrEmpty(info.configDescription))
            {
                info.configDescription = "配置文件描述";
            }
            string tableText = info.configDescription;

            tableText += "\r\n";
            List <TableConfigFieldInfo> list = new List <TableConfigFieldInfo>(info.fieldInfoDic.Values);

            for (int i = 0; i < list.Count; i++)
            {
                tableText += TypeChangeToKeyWord(list[i].defultValue.GetType());
                if (i == list.Count - 1)
                {
                    tableText += "\r\n";
                }
                else
                {
                    tableText += "\t";
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                tableText += list[i].description;
                if (i == list.Count - 1)
                {
                    tableText += "\r\n";
                }
                else
                {
                    tableText += "\t";
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                tableText += list[i].fieldName;
                if (i == list.Count - 1)
                {
                    tableText += "\r\n";
                }
                else
                {
                    tableText += "\t";
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                tableText += Value2String(list[i].defultValue);
                if (i == list.Count - 1)
                {
                    tableText += "\r\n";
                }
                else
                {
                    tableText += "\t";
                }
            }
            if (configData != null)
            {
                for (int j = 0; j < configData.configRowDataList.Count; j++)
                {
                    List <ConfigRowData> rd = configData.configRowDataList[j];
                    for (int i = 0; i < list.Count; i++)
                    {
                        object v = GetConfigRowData(rd, list[i].fieldName);
                        tableText += Value2String(v);
                        if (i == list.Count - 1)
                        {
                            tableText += "\r\n";
                        }
                        else
                        {
                            tableText += "\t";
                        }
                    }
                }
            }

            return(tableText);
        }