public static List<T> Get<T>(this SomeObject<T>,Expressions<Func<T,bool>> e){ //get the property name and value they want to check is true / false ... } TheObject().Get(x => x.PropertyName == "SomeValue");
当我将其传递给Get扩展方法时,如何获得“PropertyName”和“SomeValue”?
BinaryExpression expression = ((BinaryExpression)e.Body); string name = ((MemberExpression)expression.Left).Member.Name; Expression value = expression.Right; Console.WriteLine(name); Console.WriteLine(value);
输出:
PropertyName SomeValue
错误检查留给读者练习……