/// <summary> /// 依据列表数据的关联Id,获取关联的记录并填充到相应的属性值。 /// </summary> public static void FillProperty <TSource, TDTO>(this IReadOnlyCollection <TSource> list, Expression <Func <TSource, TDTO> > expressionProp, Func <TSource, long> funcPropId, Func <IReadOnlyCollection <long>, List <TDTO> > qryPropObj) where TDTO : IGeneralEntity { if (list.IsNullOrEmpty()) { return; } var objList = qryPropObj(list.Select(funcPropId).ToList()); if (objList.IsNullOrEmpty()) { return; } var setter = TypeExtend.GetPropertySetter(expressionProp); foreach (var item in list) { var obj = objList.ById(funcPropId(item)); if (obj != null) { setter(item, obj); } } }
/*internal static PropertyMeta<TEnt, TProp> By(Expression<Func<TEnt, TProp>> expGet) * { * var prop = ((MemberExpression) expGet.Body).Member as PropertyInfo; * return new PropertyMeta<TEnt, TProp>(prop) * { * _getter = expGet.Compile() * }; * }*/ public PropertyMeta(PropertyInfo prop, PropMetaAttribute attr) { Name = prop.Name; AttrSet = attr; Getter = TypeExtend.GetPropertyGetter <TEnt, TProp>(prop); Setter = TypeExtend.GetPropertySetter <TEnt, TProp>(prop); }