示例#1
0
        /// <summary>
        /// 获取结果
        /// </summary>
        /// <typeparam name="I">指定结果类型解析</typeparam>
        /// <param name="AnalyticalItem">对于结果类型进行额外处理</param>
        /// <returns>键值对结果</returns>
        public Dictionary <string, I> GetDictionary <I>(Func <I, I> AnalyticalItem) where I : ShineUponInfo, new()
        {
            if (CheckData.IsObjectNull(this.NeedParserType))
            {
                return(new Dictionary <string, I>());
            }
            ShineUponModelAttribute model_attr = ReflexHelp.AttributeFindOnly <ShineUponModelAttribute>(this.NeedParserType, true);

            if (CheckData.IsObjectNull(model_attr))
            {
                return(new Dictionary <string, I>());
            }
            if (CheckData.IsObjectNull(AnalyticalItem))
            {
                AnalyticalItem = i => i;
            }

            Dictionary <string, I> dic = new Dictionary <string, I>();

            PropertyInfo[] protertys = this.NeedParserType.GetProperties();
            foreach (PropertyInfo property in protertys)
            {
                ShineUponPropertyAttribute spma = ReflexHelp.AttributeFindOnly <ShineUponPropertyAttribute>(property, true);
                if (CheckData.IsObjectNull(spma) || !spma.IsShineUpon)
                {
                    continue;
                }
                ExplainAttribute attr_explain = ExplainAttribute.Extract(property);
                I info = ReflexHelp.CreateNewObject <I>();
                info.Name     = property.Name;
                info.Property = property;
                info.Explain  = attr_explain;

                // 钩子: 子类处理解析内容
                info = AnalyticalItem(info);
                if (CheckData.IsObjectNull(info))
                {
                    continue;
                }
                dic.Add(info.Name, info);
            }
            return(dic);
        }
示例#2
0
        /// <summary>
        /// 数据行 转为 单个映射模型
        /// </summary>
        /// <param name="row">数据行</param>
        /// <returns>单个映射模型</returns>
        public M DataRowToModel(DataRow row)
        {
            if (CheckData.IsSizeEmpty(row))
            {
                return(null);
            }
            M model = ReflexHelp.CreateNewObject <M>();

            ColumnInfo[] columninfos = this.Parser.GetList();
            foreach (ColumnInfo item in columninfos)
            {
                if (CheckData.IsObjectNull(item))
                {
                    continue;
                }
                object value = row[item.Property.Name];
                this.Parser.SetValue_Object(item, model, value);
            }
            return(model);
        }