表达式树有用的一些实例是什么? [英] What are some instances in which expression trees are useful?

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

问题描述

我完全理解表达树的概念,但是我很难找到它们有用的情况。有没有可以应用表达式树的特定实例?还是只能用作代码的传输机制?我觉得我在这里遗漏了一些东西。谢谢!

解决方案


还是只能用作代码的传输机制?


作为代码的执行机制很有用。使用解释器模式,可以直接解释表达式树。这是有用的,因为它非常容易和快速地实现。这样的口译员是普遍存在的,即使在似乎没有解释任何东西的情况下也是如此。用于打印嵌套结构。


I completely understand the concept of expression trees, but I am having a hard time trying to find situations in which they are useful. Is there a specific instance in which expression trees can be applied? Or is it only useful as a transport mechanism for code? I feel like I am missing something here. Thanks!

解决方案

Or is it only useful as a transport mechanism for code?

It's useful as an execution mechanism for code. Using the interpreter pattern, expression trees can directly be interpreted. This is useful because it's very easy and fast to implement. Such interpreters are ubiquitous and used even in cases that don't seem to "interpret" anything, e.g. for printing nested structures.

这篇关于表达式树有用的一些实例是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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