public override List <ConditionPropery> Get <TSource>() { List <ConditionPropery> cps = new List <ConditionPropery>(); Type sourceType = typeof(TSource); PropertyInfo[] props = sourceType.GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { ConditionAttribute conAttr = attr as ConditionAttribute; if (conAttr != null) { ConditionPropery conProp = new ConditionPropery(); conProp.Key.PropertyName = prop.Name; conProp.Key.PropertyType = prop.PropertyType; conProp.action = conAttr.action; cps.Add(conProp); } } } return(cps); }
public static Func <TSource, bool> GetWhereFunc(ConditionPropery conProp) { lock (lockobj) { curConProp = conProp; } return(FuncMethod); }
public ConditionProperyCollectionBuilder <TSource> AddConditionValue(string name, object value) { ConditionPropery conp = conProps.FirstOrDefault(cp => cp.Key.PropertyName == name); if (conp != null) { conp.PropertyValue = value; } return(this); }
public static Expression <Func <T, bool> > GetMeberEqualValueLambda <T>(ConditionPropery conProp) { var param = Expression.Parameter(typeof(T), "p"); Expression body = param; foreach (var member in conProp.Key.PropertyName.Split('.')) { body = Expression.PropertyOrField(body, member); } var convert = Expression.Convert(body, conProp.Key.PropertyType); Expression constvalue = Expression.Constant(conProp.PropertyValue); var equal = Expression.Equal(convert, constvalue); return((Expression <Func <T, bool> >)Expression.Lambda(equal, param)); }
public static Expression <Func <TSource, bool> > GetWhereExpression(ConditionPropery conProp) { return(ExpressionHelper.GetMeberEqualValueLambda <TSource>(conProp)); }