https://github.com/mustaddon/csharpeval
Compile and execute C# code at program runtime
https://github.com/mustaddon/csharpeval
Last synced: 10 months ago
JSON representation
Compile and execute C# code at program runtime
- Host: GitHub
- URL: https://github.com/mustaddon/csharpeval
- Owner: mustaddon
- License: mit
- Created: 2019-04-16T20:39:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-17T20:05:03.000Z (about 7 years ago)
- Last Synced: 2024-12-16T15:18:07.586Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 21.5 KB
- Stars: 7
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSharpEval [](http://badge.fury.io/nu/RandomSolutions.CSharpEval)
Compile and execute C# code at program runtime
## Examples
*Simple math expression*
```csharp
var result = CSharpEval.Execute("A + B", new { A = 2, B = 3});
```
*Linq sample*
```csharp
var result = CSharpEval.Execute(@"
var list = new List() { 1, 2, 3, 4, 5 };
return list.Where(x => x < K).Sum(x => x);
", new { K = 5 });
```
*Adding references*
```csharp
CSharpEval.Execute("Console.WriteLine(A)",
new { A = ExternalLib.SomeEnum.Sample },
new[] { Assembly.GetAssembly(typeof(ExternalLib.SomeEnum)) });
```