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

MaxShoshin/ExpressionCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Parse C# expression and create DynamicMethod

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages