实际使用前pression树 [英] Practical use of expression trees

查看:156
本文介绍了实际使用前pression树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

防爆pression树是一个不错的功能,但什么是它的实际用途?它们可用于某种code生成或元编程或一些这样?

Expression trees are a nice feature, but what are its practical uses? Can they be used for some sort of code generation or metaprogramming or some such?

推荐答案

随着乔恩指出,我使用他们提供的通用操作符使用.NET 3.5。我也(在MiscUtil再次)使用它们来提供快速访问到非默认的构造函数(你不能使用 Delegate.CreateDelegate 与构造,但防爆pression 正常工作)。

As Jon notes, I use them to provide generic operators with .NET 3.5. I also use them (again in MiscUtil) to provide fast access to non-default constructors (you can't use Delegate.CreateDelegate with constructors, but Expression works fine).

的手动创建的前pression树木其他用途:

Other uses of manually created expression trees:

  • object cloning
  • dynamic LINQ sorting
  • as a compiler

不过说真的,防爆pression是编写任何动态code的一个非常通用的方式。远远高于 Reflection.Emit的简单,我的钱,简单到codeDOM理解。而在.NET 4.0中,你必须甚至更多的选择使用。我通过防爆pression 在我的博客

But really, Expression is a very versatile way of writing any dynamic code. Much simpler than Reflection.Emit, and for my money, simpler to understand than CodeDOM. And in .NET 4.0, you have even more options available. I show the fundamentals of writing code via Expression on my blog.

这篇关于实际使用前pression树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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