Nested expression trees

I've installed Orcas and began to play with lambdas and expression trees.
Is it allowed to use 'nested' exression trees?
I mean:

Code Snippet


using System;
using System.Linq;
using System.Linq.Expressions;

namespace Nikov.Linq
{
using Expr = Expression<Func<int, int>>;
class Program
{
static void Main()
{
Expression<Func<int, Expr>> b = (y => (Expr)(x => 2 * x));
}
}
}

Currently, it compiles without any errors, but throws InvalidProgramException when run.
[697 byte] By [nikov] at [2008-3-5]
# 1

Hi Nikov,

I tried your example with the execution part:

using System;

using System.Linq;

using System.Linq.Expressions;

namespace Nikov.Linq

{

using Expr = Expression<Func<int, int>>;

class Program

{

static void Main()

{

Expression<Func<int, Expr>> b = (y => (Expr)(x => 2 * x));

Func<int, Expr> f1 = b.Compile();

Func<int, int> f2 = f1(1).Compile();

int r = f2(1);

}

}

}

And was able to run, so it seems you are running into a bug that is fixed in the internal version, thanks for reporting it.

Marcelo.

MarceloGuerra-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Visual C# Orcas...

Visual Studio Orcas

Site Classified