如何获取表达式的值
我有一个使用 Linq 表达式的函数:
private Expression GetFieldValueExpression(ParameterExpression parameter, string fieldName)
{
Expression properyIndexExpression = System.Linq.Expressions.Expression.Constant (fieldName, typeof(string));
IndexExpression fieldValueExpression = System.Linq.Expressions.Expression.Property(parameter, "Item", new Expression[] { properyIndexExpression });
return Expression.Property(fieldValueExpression, "Value");
}
Expression.Property(fieldValueExpression, "Value")
返回的值是字符串类型。
我不知道如何得到它。我知道我必须创建一个 lambda 并编译它,但我不知道如何做。
谢谢您的宝贵时间。
I have this function that uses Linq expressions:
private Expression GetFieldValueExpression(ParameterExpression parameter, string fieldName)
{
Expression properyIndexExpression = System.Linq.Expressions.Expression.Constant (fieldName, typeof(string));
IndexExpression fieldValueExpression = System.Linq.Expressions.Expression.Property(parameter, "Item", new Expression[] { properyIndexExpression });
return Expression.Property(fieldValueExpression, "Value");
}
The value returned by Expression.Property(fieldValueExpression, "Value")
is of type string.
I don't know how to get it. I know that i must create a lambda and compile it, but i don't know how.
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您正在寻找这样的代码:
该代码假设一些如下所示的测试类(基本上索引器属性仅返回输入,但为大写 - 一个简单的示例,但适用于测试):
Perhaps you are looking for code like this:
that code assumes some test classes that look like this (basically the indexer property just returns the input but in upper case - a trivial example but works for testing):