.NET 4.0:什么是Expression.Reduce()呢? [英] .NET 4.0: What does Expression.Reduce() do?

查看:261
本文介绍了.NET 4.0:什么是Expression.Reduce()呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用工作了几天表达式树,我很好奇,想知道是什么Expression.Reduce()一样。该 MSDN文档是不是很有用的,因为它只是说,它减少的表达。以防万一,我试过一个例子(见下文),以检查是否该方法包括数学减少,但这似乎并不如此。



有谁知道这是什么方法做,并且可以提供一个简单的例子说明在行动呢?任何好的资源,在那里



非常感谢



编辑:?!替换为[X => X + X ]由[X =>(X + X + X)+ Math.Exp(X + X + X)]

 静无效的主要(字串[] args)
{
表达式来; Func键<双层,双>> FUNC = X => (X + X + X)+ Math.Exp(X + X + X);
Console.WriteLine(FUNC);
表达r_func = func.Reduce();
Console.WriteLine(r_func); //这个打印出相同的Console.WriteLine(FUNC)
{


解决方案

您需要查看该文件为expr树-spec.doc此处的 http://dlr.codeplex.com/wikipage?title=Docs%20and%20specs&ref​​erringTitle=Documentation



这是表达式树的规格。阅读2.2可还原节点和4.3.5减少方法部分。



基本上,这个方法适用于实施或移植他们的动态汉语语言到.NET的人。使他们能够创建自己的节点,可以降低标准表达式树的节点,并可以进行编译。有在表达式目录树API一些还原节点,但我不知道你是否能得到任何实际的例子(因为所有的标准表达式节点编译无论如何,作为最终用户,你可能不关心他们是否是减少幕后与否)。



是的,MSDN文档在这方面非常基本的,因为信息和文档的语言实现者的主要来源是的http://dlr.codeplex.com/


I've been working with expression trees for a few days now and I'm curious to know what Expression.Reduce() does. The msdn documentation is not very helpful as it only states that it "reduces" the expression. Just in case, I tried an example (see below) to check if this method included mathematical reduction, but this doesn't seem to be the case.

Does anyone know what this method does and is it possible to provide a quick example showing it in action? Any good resources out there?

Thanks a lot!

Edit: Replaced [x => x + x] by [x => (x + x + x) + Math.Exp(x + x + x)]

    static void Main(string[] args)
    {
        Expression<Func<double, double>> func = x => (x + x + x) + Math.Exp(x + x + x);
        Console.WriteLine(func);
        Expression r_func = func.Reduce();
        Console.WriteLine(r_func); // This prints out the same as Console.WriteLine(func)
    {

解决方案

The document you need to look at is "expr-tree-spec.doc" here: http://dlr.codeplex.com/wikipage?title=Docs%20and%20specs&referringTitle=Documentation

This is the specification for the expression trees. Read the "2.2 Reducible Nodes" and "4.3.5 Reduce Method" sections.

Basically, this method is intended for people implementing or porting their dynamic langauges to .NET. So that they can create their own nodes that can "reduce" to standard expression tree nodes and can be compiled. There are some "reducible" nodes in the expression trees API, but I don't know whether you can get any practical examples (since all standard expression nodes compile anyway, as the end-user you probably do not care whether they are "reduced" behind the scenes or not).

Yes, MSDN documentation is very basic in this area, because the main source of info and docs for language implementers is http://dlr.codeplex.com/

这篇关于.NET 4.0:什么是Expression.Reduce()呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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