LINQ 表达式树最多可以做什么? [英] What is the max LINQ Expression Trees can do?

查看:39
本文介绍了LINQ 表达式树最多可以做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LINQ 表达式树最多可以做多少?

What is the maximum that LINQ expression Tree can do?

它可以定义一个类吗?一个带有所有声明名称、修饰符、参数类型和返回类型的方法怎么样?

Can it define a class? How about a method, with all the declared name, modifiers, parametertype and return type?

程序必须始终定义树本身吗?是否可以从给定的 C# 文件生成树?

Must the program always define the tree itself? Is it possible to generate the tree from a given C# file?

推荐答案

在 C# 3 中,表达式树可以表示表达式.由此得名.而且它们被进一步限制为 C# 表达式的一个子集——没有赋值表达式,没有涉及指针类型的表达式,等等.

In C# 3, expression trees can represent expressions. Hence the name. And they are further restricted to a subset of C# expressions -- no assignment expressions, no expressions involving pointer types, and so on.

在 C# 4 附带的库中,我们扩展了表达式树,以支持语句树.但是,C# 4 不会自动将语句 lambda 转换为语句树".

In the libraries that will ship with C# 4, we have extended the expression tree library to also support statement trees. However, C# 4 will NOT automatically translate a statement-lambda into a "statement tree".

这是一个明显且有用的特性,我们只是没有时间在 C# 4 中使用它.我们将在假设的未来版本中考虑它.如果您有一个非常棒的语句树用户场景,我很乐意听到.

That is an obvious and useful feature which we simply did not have time to get to for C# 4. We'll consider it for hypothetical future versions. If you have a really great user scenario for statement trees, I'd love to hear it.

明显的进一步扩展是声明树,它代表类声明、结构声明等.在 C# 语言和表达式树库之间具有 完全的同象性会很棒.它将启用各种有趣的元编程场景.但这不会很快发生,所以不要抱有希望.这更像是我的一个可能永远不会实现的长期梦想.

The obvious further extension to all that is declaration trees, which would represent class declarations, struct declarations, and so on. Having total homoiconicity between the C# language and the expression tree library would be awesome. It would enable all kinds of interesting metaprogramming scenarios. But that will not happen any time soon, so do not get your hopes up. That's more of a long-term dream of mine which might never happen.

这篇关于LINQ 表达式树最多可以做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆