我正在尝试编写一个可以这样调用的方法:
var myCommand = Command.Where(x => x.Name == "grep" && x.Switch == "x");
我想要做的是解析结果表达式,如下所示:
public static string FindBy(Expression<Func<T, bool>> expression)
{
var condition1Key = ? //condition1Key = "Name"
var condition1Value = ? //condition1Value = "grep"
var condition2Key = ? //condition1Key = "Switch"
var condition2Value = ? //condition1Value = "x"
return string.Format("Looking for commands with {0} = {1} and {2} = {3}",
condition1Key, condition1Value,
condition2Key, condition2Value);
}
我确实找到了这篇文章,但它已经很老了,从未收到过正确的答案。