给定 type 的任意表达式,Expression<Func<int>>我如何获得所有可能但不一定会影响结果的对象的列表。
我正在寻找这样的功能:
IEnumerable<object> GetFactors(Expression<Func<int>> expression)
{
//return a list of all objects in the expression that affect the result.
}
示例 1
Expression<Func<int>> expression = () => a + b;
where aand bare ints,GetFactors将返回一个IEnumerable<object>包含aand b。
示例 2
Expression<Func<int>> expression = () => obj1 != obj2 ? a + b : c + d;
GetFactors将返回IEnumerable<object>包含obj1, obj2, a, b, c, 和d.