How to compile a c# Lambda expression to a System.Linq.Expression.

C

Colin Han

Hi, all,
If I write follow code in c# method. The IDE will compile it to a complex construct method of System.Linq.Expression.
Expression<Func<int>> ex = () => 10;
will be compile to:
Expression<Func<int>> ex = Expression.Lambda<Func<int>> (Expression.Literal(10))
It is so smart. I can travel in this expression tree. I can do some smart abilities on this design.

Now, I want write a console application. If user input follow string from console,
() => 10
I want make a LambdaExpression object and execute it in my context.
I can use CodeDom to compile some c# code to a dynamic assembly. But I have not found a utility to compile c# code to an expression object.

How to compile a c# Lambda expression to a Expression object? Help me. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top