/// <summary> /// 获取信息列表 /// </summary> public ColumnInfo[] GetList() { Dictionary <string, ColumnInfo> dic = this.GetDictionary <ColumnInfo>(info => { info.Attribute = ReflexHelp.AttributeFindOnly <ColumnAttribute>(info.Property); return(CheckData.IsObjectNull(info.Attribute) ? null : info); }); List <ColumnInfo> list = new List <ColumnInfo>(dic.Values); if (IsNeedSort()) { list.Sort(SortMethod); } return(list.ToArray()); }
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(), }, }); }
public CaseModel Func_AttributeFindOnly_Inherit() { return(new CaseModel() { NameSign = @"继承查找", ExeEvent = () => { Func <TestModel, bool, bool, bool> method = (model, isFindInherit, isNull) => { // isFindInherit = true; // 查找继承链 Type type = model.GetType(); EntityTableAttribute et_attr = ReflexHelp.AttributeFindOnly <EntityTableAttribute>(type, isFindInherit); // isNull = true; // 是否允许为空 if (CheckData.IsObjectNull(et_attr) != isNull) { Console.WriteLine("Type: {0} isFindInherit: {1} 不符合 isNull: {2}", type.Name, isFindInherit, isNull); return false; } return true; }; if (!method(new TestModel(), true, false)) { return false; } if (!method(new TestModel(), false, false)) { return false; } if (!method(new A(), true, false)) { return false; } if (!method(new A(), false, true)) { return false; } if (!method(new B(), true, false)) { return false; } if (!method(new B(), false, true)) { return false; } return true; }, }); }
/// <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); }