3 ms·
ah sorry, the naming threw me off. TIL you can manipulate/compile ASTs in C#! https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions?view=netframe
by uryga 7y ago
ah sorry, the naming threw me off. TIL you can manipulate/compile ASTs in C#!
https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.linq.expr...
i guess all the macro stuff is under System.Linq.Expressions because LINQ expressions like
from score in scores
where score > 80
select score
aren't just for SQL and can desugar to arbitrary C# code, is that right?
- lostmsu 7y agoI think they are limited quite a bit. E.g. do not support classes, latest C# features, etc. They were made exactly for SQL among other things. With SQL target your example will use this feature: scores will be IQueryable, and "IQueryable.Where" will take Expression, which C# compiler will generate from "score > 80" during compilation. Then the specific database engine will convert that "Expression" instance to SQL query for execution. Of course, there are other ways to generate more .NET code at runtime. But not at compile time, which I wish we had.