我正在解析一个表达式树。如果给定一个ExpressionType.MemberAccess节点类型,我如何获取该字段的值?
根据C# MSDN文档: MemberAccess是表示从字段或属性中读取的节点。
一个代码片段将非常、非常有帮助。提前感谢!!!
我的代码大致如下:
public static List<T> Filter(Expression<Func<T, bool>> filterExp)
{
//the expression is indeed a binary expression in this case
BinaryExpression expBody = filterExp.Body as BinaryExpression;
if (expBody.Left.NodeType == ExpressionType.MemberAccess)
//do something with ((MemberExpressionexpBody.Left).Name
//right hand side is indeed member access. in fact, the value comes from //aspdroplist.selectedvalue
if (expBody.Right.NodeType == ExpressionType.MemberAccess)
{
//how do i get the value of aspdroplist.selected value?? note: it's non-static
}
//return a list
}