How to run dynamic code at runtime (part 1) In my previous post I talked about how to read LINQ expressions using an ExpressionVisitor , however reading isn’t the only thing you can do with expressions: you can build them at runtime! If you’ve ever used reflection you’re probably aware that you shouldn’t use them in performance-critical situations as they’re one of the slowest parts of .NET, but what if you desperately need to use it? Enter the world of expression-building. Before I show you how anything works, I want you to compare speeds: RawAccess: 00:00:00.0000344 b*1,0 (3,44E-06ms per iteration) ReflectionNoCache: 00:00:00.0018118 b*52,7 (0,00018118ms per iteration) ReflectionWithCache: 00:00:00.0009518 b*27,7 (9,518E-05ms per iteration) ExpressionNoCache: 00:00:00.9333534 b*27132,4 (0,09333534ms per iteration) ExpressionWithCache: 00:00:00.0000424 b*1,2 (4,24E-06ms per iteration) Benchmark ran with .NET Core 2.2 on an AMD Ryzen 2400G @ 3.85Ghz and Windows 10...
Blog about programming technologies like C# and ASP.NET Core