Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Latest commit

 

History

History
18 lines (13 loc) · 854 Bytes

README.md

File metadata and controls

18 lines (13 loc) · 854 Bytes

ExpressionCompiler

Create DynamicMethod based on text expression. Supports full C# expression syntax.

Roslyn Scripting provide awesome compilation of any C# expression. Roslyn.Scripting has one disadvantage now: for any single script parse it creates separate assembly in current AppDomain. Now there is no ability to unload such assemblies even they are not used anymore.

ExpressionCompiler creates DynamicMethod based on your expression without loading additional assemblies in the app domain. DynamicMethod can be garbage collected as usual class when it no longer used.

Usage:

Func<int> calculator = new ExpressionCompiler(
        "return (int)Math.Round(Math.PI);")
                .WithUsing("System")
                .Returns(typeof(int))
                .Compile<Func<int>>();

Console.WriteLine(calculator.Invoke()); // Prints 3