Esempio n. 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);
        }