Example #1
0
    public void LoadConfigByLine(ConfigData data, ConfigSheetLine content)
    {
        Debug.Assert(data != null && content != null);

        FieldInfo[] infos = GetType().GetFields();
        for (int i = 0; i < infos.Length; ++i)
        {
            FieldInfo info       = infos[i];
            int       fieldIndex = data.GetFieldByName(info.Name);
            if (fieldIndex == -1)
            {
                continue;
            }

            object fieldValue = content.GetData(fieldIndex);
            int    fieldType  = data.GetDataType(fieldIndex);
            switch (fieldType)
            {
            case ConfigDataType.UNKNOWN:
            case ConfigDataType.INT:
            case ConfigDataType.BOOL:
            case ConfigDataType.FLOAT:
            case ConfigDataType.LONG:
            case ConfigDataType.DOUBLE:
            case ConfigDataType.STRING:
            case ConfigDataType.ENUM:
            case ConfigDataType.JSON:
                info.SetValue(this, fieldValue);
                break;

            case ConfigDataType.ARRAY:
                Type dataType    = info.FieldType;
                Type elementType = dataType.GetElementType();
                if (dataType.IsArray && (elementType == typeof(int) || elementType.IsEnum || elementType == typeof(bool) || elementType == typeof(float)) || elementType == typeof(long) || elementType == typeof(double) || elementType == typeof(string))
                {
                    DecodeArrayValue(info, fieldValue, elementType);
                }
                else
                {
                    DecodeSpecialValue(info, fieldValue);
                }
                break;

            case ConfigDataType.CUSTOM:
                DecodeSpecialValue(info, fieldValue);
                break;

            case ConfigDataType.DATETIME:
                if (!string.IsNullOrEmpty((string)fieldValue))
                {
                    info.SetValue(this, Convert.ToDateTime(fieldValue));
                }
                break;
            }
        }
    }
Example #2
0
    public object GetDataByRow(int row, int field)
    {
        ConfigSheetLine dataByRow = GetDataByRow(row);

        if (dataByRow != null)
        {
            return(dataByRow.GetData(field));
        }
        return(null);
    }
Example #3
0
    public object GetData(int id, int field)
    {
        ConfigSheetLine data = GetData(id);

        if (data != null)
        {
            return(data.GetData(field));
        }
        return(null);
    }
Example #4
0
    public int[] fieldTypes;    // 字段类型列表
    //public byte FileType; // 配置表类型:1-制表符分割的csv文件,2-xml文件
    //public string xmlText;

    public ConfigSheetLine GetData(int id)
    {
        for (int i = 0; i < this.data.Length; ++i)
        {
            ConfigSheetLine line = this.data[i];
            if (((int)line.GetData(0)) == id)
            {
                return(line);
            }
        }
        return(null);
    }
Example #5
0
    public object GetDataByRow(int row, string fieldName)
    {
        ConfigSheetLine dataByRow = GetDataByRow(row);

        if (dataByRow != null)
        {
            int field = GetFieldByName(fieldName);
            if (field >= 0)
            {
                return(dataByRow.GetData(field));
            }
        }
        return(null);
    }
Example #6
0
    public string GetCommmonValue(string key)
    {
        if (_commonData == null)
        {
            _commonData = GetConfig("Common") as ConfigData;
        }

        ConfigSheetLine line = _commonData.GetDataByName(key);

        if (line != null)
        {
            return((string)line.GetData(1, ConfigDataType.STRING));
        }
        return(null);
    }
Example #7
0
    public void LoadConfigByLine(ConfigData data, ConfigSheetLine content)
    {
        if (data != null && content != null)
        {
            FieldInfo[] fields = GetType().GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo fi = fields[i];

                int fieldIndex = data.GetFieldByName(fi.Name);
                if (fieldIndex != -1)
                {
                    int    defineType = data.GetDataType(fieldIndex);
                    int    typeindex  = data.GetTypeIndex(fieldIndex);
                    object ovalue     = content.GetData(typeindex, defineType);

                    switch (defineType)
                    {
                    case ConfigDataType.INT:
                    case ConfigDataType.ENUM:
                    case ConfigDataType.BOOL:
                    case ConfigDataType.FLOAT:
                    case ConfigDataType.STRING:
                        fi.SetValue(this, ovalue);
                        break;

                    case ConfigDataType.ARRAY:
                        Type type  = fi.FieldType;
                        Type stype = type.GetElementType();
                        if (type.IsArray && (stype == typeof(int) || stype == typeof(string) || stype == typeof(float)))
                        {
                            DecodeArrayValue(fi, ovalue, stype);
                        }
                        else
                        {
                            DecodeSpecialValue(fi, ovalue);
                        }
                        break;

                    case ConfigDataType.CUSTOM:
                        //交由各个具体的子列去实现解析
                        DecodeSpecialValue(fi, ovalue);
                        break;
                    }
                }
            }
        }
    }
Example #8
0
    public ConfigSheetLine[] GetLinesByFieldNameValue(string[] fieldNames, object[] values)
    {
        Debug.Assert(((fieldNames != null) && (values != null)) && (fieldNames.Length == values.Length));

        int length = fieldNames.Length;

        int[] fieldIndexs = new int[length];
        for (int i = 0; i < length; i++)
        {
            fieldIndexs[i] = GetFieldByName(fieldNames[i]);
            if (fieldIndexs[i] < 0)
            {
                return(null);
            }
        }
        List <ConfigSheetLine> list = null;

        for (int i = 0; i < this.data.Length; ++i)
        {
            ConfigSheetLine line = this.data[i];
            bool            flag = true;
            for (int j = 0; j < length; j++)
            {
                if (!line.GetData(fieldIndexs[j]).Equals(values[j]))
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                if (list == null)
                {
                    list = new List <ConfigSheetLine>();
                }
                list.Add(line);
            }
        }
        if (list != null)
        {
            return(list.ToArray());
        }
        return(null);
    }