Skip to content

Instantly share code, notes, and snippets.

@Fosna
Created January 22, 2016 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fosna/c239f71f1a11bebbca1e to your computer and use it in GitHub Desktop.
Save Fosna/c239f71f1a11bebbca1e to your computer and use it in GitHub Desktop.
It's suggested to use LINQPad 5 (download link: http://www.linqpad.net/download.aspx). How to build expression tree without lambda function. Use dynamic LINQ.
Expression<Func<int, int, int>> addExp = (a, b) => a + b;
Console.WriteLine(addExp);
var aArg = Expression.Parameter(typeof(int), "a");
var bArg = Expression.Parameter(typeof(int), "b");
var addBody = Expression.Add(aArg, bArg);
var buildAddExp = (Expression<Func<int, int, int>>)Expression.Lambda(addBody, aArg, bArg);
Console.WriteLine(buildAddExp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment