我正在解析一个表达式树。给定 ExpressionType.MemberAccess 的 NodeType,我如何获取该字段的值?
来自 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
}