示例#1
0
        private void AddSplitRangeColumn(PropertyInfo pi, string valueStr, object model)
        {
            IList      list      = pi.GetValue(model, null) as IList;
            List <int> rangeList = SplitColumnValueParser.splitRangeElement(valueStr);

            if (rangeList == null)
            {
                Debug.LogWarning(string.Format("AddSplitRangeColumn value {0} parse error", valueStr));
            }
            foreach (var item in rangeList)
            {
                list.Add(item);
            }
        }
示例#2
0
        private IList GetSplitItemList(Type type, string valueStr, bool isCustomType, ref IList list)
        {
            SplitColumnValueParser parser    = new SplitColumnValueParser();
            List <string>          valueList = parser.splitMultiValue2List(valueStr);

            if (isCustomType)
            {
                foreach (string value in valueList)
                {
                    var            item         = Activator.CreateInstance(type);
                    List <string>  valFieldList = parser.splitDiffElement2List(value);
                    PropertyInfo[] piArr        = type.GetProperties();
                    if (valFieldList.Count != piArr.Length)
                    {
                        Debug.Log(string.Format("splitColumn value count {0} property {1} is not match", valFieldList.Count, piArr.Length));
                    }

                    foreach (PropertyInfo pi in piArr)
                    {
                        var fieldAtbArr = pi.GetCustomAttributes(typeof(DbSplitFieldAttribute), false);
                        if (fieldAtbArr.Length != 0)
                        {
                            var    fieldAtb   = fieldAtbArr[0] as DbSplitFieldAttribute;
                            string fieldValue = "";
                            bool   isHasData  = (fieldAtb.Index <= valFieldList.Count);
                            if (isHasData)
                            {
                                fieldValue = valFieldList[fieldAtb.Index - 1];
                                if (fieldValue == "")
                                {
                                    isHasData = false; // 如果解析出来的是"", 仍然认为其数据为默认值
                                }
                            }

                            if (fieldAtb.IsCustomType)
                            {
                                if (fieldAtb.Type.IsPrimitive) // 是否是自定义的基础属性
                                {
                                    if (isHasData)             // 有数据的才进行这些处理, 对应字符串段没填的话, 就用默认值
                                    {
                                        // 这是list
                                        List <string> subValList = parser.splitMultiValue2List(fieldValue);
                                        var           subList    = pi.GetValue(item, null) as IList;
                                        foreach (var subVal in subValList)
                                        {
                                            if (fieldAtb.Type == typeof(int))
                                            {
                                                if (!string.IsNullOrEmpty(subVal)) // 如果解析出空串,说明列表为空
                                                {
                                                    subList.Add(Convert.ToInt32(subVal));
                                                }
                                            }
                                            else if (fieldAtb.Type == typeof(string))
                                            {
                                                subList.Add(subVal);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    AddSplitColumn(fieldAtb.Type, pi, fieldValue, true, item);
                                }
                            }
                            else
                            {
                                if (isHasData) // 有数据才回写, 不然就是默认值
                                {
                                    // 设置非自定义值
                                    // bool值特殊处理
                                    if (pi.PropertyType == typeof(bool))
                                    {
                                        pi.SetValue(item, Convert.ToInt32(fieldValue) == 1, null);
                                    }
                                    else if (pi.PropertyType == typeof(int))
                                    {
                                        pi.SetValue(item, Convert.ToInt32(fieldValue), null);
                                    }
                                    else
                                    {
                                        if (pi.PropertyType == typeof(string))
                                        {
                                            pi.SetValue(item, fieldValue, null);
                                        }
                                        else
                                        {
                                            pi.SetValue(item, fieldValue, null);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    list.Add(item);
                }
            }
            else
            {
                if (type == typeof(int))
                {
                    foreach (string value in valueList)
                    {
                        try
                        {
                            list.Add(Convert.ToInt32(value));
                        }
                        catch (Exception e)
                        {
                            Debug.LogWarning(string.Format("GetSplitItemList type {0} valueStr {1}  value{3} Convert.ToInt32 found exception {2}", type, valueStr, e.ToString(), value));
                        }
                    }
                }
                else
                {
                    foreach (string value in valueList)
                    {
                        list.Add(value);
                    }
                }
            }

            return(list);
        }