How can I evaluate a C# expression dynamically?
Old topic, but considering this is one of the first threads showing up when googling, here is an updated solution. You can use Roslyn’s new Scripting API to evaluate expressions. If you are using NuGet, just add a dependency to Microsoft.CodeAnalysis.CSharp.Scripting. To evaluate the examples you provided, it is as simple as: var result = … Read more