public CaseModel Func_AttributeFindOnly()
        {
            return(new CaseModel()
            {
                NameSign = @"查找元数据某一种特性",
                ExeEvent = () => {
                    Type type = typeof(TestModel);
                    Func <string, bool, bool, bool> method = (name, isNull_explain, isNull_column) => {
                        PropertyInfo pi_id = type.GetProperty(name);
                        ExplainAttribute explain = ReflexHelp.AttributeFindOnly <ExplainAttribute>(pi_id);
                        if (CheckData.IsObjectNull(explain) != isNull_explain)
                        {
                            Console.WriteLine("name: {0} isNull_explain: {1} 错误", name, isNull_explain);
                            return false;
                        }
                        ColumnAttribute column = ReflexHelp.AttributeFindOnly <ColumnAttribute>(pi_id);
                        if (CheckData.IsObjectNull(column) != isNull_column)
                        {
                            Console.WriteLine("name: {0} isNull_column: {1} 错误", name, isNull_column);
                            return false;
                        }
                        return true;
                    };
                    if (!method("id", false, false))
                    {
                        return false;
                    }
                    if (!method("Money", true, false))
                    {
                        return false;
                    }
                    if (!method("Name", false, true))
                    {
                        return false;
                    }
                    if (!method("Remark", true, true))
                    {
                        return false;
                    }
                    return true;
                },

                SonCases = new CaseModel[] {
                    Func_AttributeFindOnly_Inherit(),
                },
            });
        }
Example #2
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);
        }