Jan 30, 2009

Expression evaluation, thinking again

I recently discussed .NET runtime expression evaluation. Integrating some sample code into your productive applications may have some smells; so this may not be your prefered way to solve simple business logic expression evaluation issues.

Reading a blog from Brad Abrams about Avoiding Custom Delegates explaining

Expression<…> represents function definitions that can be compiled and subsequently invoked at runtime but can also be serialized and passed to remote processes. Continuing with our example:

            Expression<Func<int, int, double>> expression = (x, y) => (double)x / (double)y;

            Func<int, int, double> divide = expression.Compile();

            Console.WriteLine(divide(2, 3));

No comments:

Post a Comment