3 ms·
My favorite feature of .Net is probably expressions trees. (https://blogs.msdn.microsoft.com/charlie/2008/01/31/expression-tree-basics/ https://blogs.msdn.micro
by scarface74 9y ago
My favorite feature of .Net is probably expressions trees. (https://blogs.msdn.microsoft.com/charlie/2008/01/31/expression-tree-basics/ https://blogs.msdn.microsoft.com/charlie/2008/01/31/expressi...).
They have been around since 2008.
A lot of non .Net people think that expression trees are just lambdas, but they are so much more powerful.
If you have a method that has a signature:
Find(Expression<Func<Employee,bool>> query) {…}
And you call it by
foo.Find(e => e.id == 5);
That expression is treated as “data” not code. Meaning if your Find command is searching for Employees in SQL Server using Entity Framework, it will be translated to sql that runs on the server. If you’re using Mongo, it will be translated into MongoQuery. When you are unit testing you can mock it out, and process any given query against an in memory List<People>.
If you are crazy enough, you can even move it out into a micro service and parse the expression tree yourself into a query object that you send to an API.
- alkonaut 9y agoCode quotations is similar in F#, but if you add F#'s type providers you can reach an entirely new level of crazy.