VOOZH about

URL: https://www.nuget.org/packages/Ecng.Compilation/

⇱ NuGet Gallery | Ecng.Compilation 1.0.316




👁 Image
Ecng.Compilation 1.0.316

dotnet add package Ecng.Compilation --version 1.0.316
 
 
NuGet\Install-Package Ecng.Compilation -Version 1.0.316
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ecng.Compilation" Version="1.0.316" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Compilation" Version="1.0.316" />
 
Directory.Packages.props
<PackageReference Include="Ecng.Compilation" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ecng.Compilation --version 1.0.316
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ecng.Compilation, 1.0.316"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ecng.Compilation@1.0.316
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ecng.Compilation&version=1.0.316
 
Install as a Cake Addin
#tool nuget:?package=Ecng.Compilation&version=1.0.316
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ecng.Compilation

Dynamic code compilation infrastructure for C#, F#, and Python. Compile code at runtime, manage references, and cache assemblies.

Overview

This library provides a unified interface for runtime code compilation supporting multiple languages through specialized providers.

Core Types

ICompiler Interface

The main abstraction for compilers.

public interface ICompiler
{
 string Extension { get; } // e.g., ".cs", ".fs", ".py"
 bool IsAssemblyPersistable { get; } // Can save compiled assembly
 bool IsTabsSupported { get; } // Language supports tabs
 bool IsCaseSensitive { get; } // Language is case-sensitive
 bool IsReferencesSupported { get; } // Supports external references

 ICompilerContext CreateContext();

 Task<CompilationResult> Compile(
 string name,
 IEnumerable<string> sources,
 IEnumerable<(string name, byte[] body)> refs,
 CancellationToken ct = default);

 Task<CompilationError[]> Analyse(
 object analyzer,
 IEnumerable<object> analyzerSettings,
 string name,
 IEnumerable<string> sources,
 IEnumerable<(string name, byte[] body)> refs,
 CancellationToken ct = default);
}

CompilationResult

Result of a compilation operation.

var result = await compiler.Compile("MyCode", sources, references);

if (result.HasErrors)
{
 foreach (var error in result.Errors)
 {
 Console.WriteLine($"{error.Type}: {error.Message}");
 Console.WriteLine($" Line {error.Line}, Column {error.Column}");
 }
}
else
{
 // Get compiled assembly
 Assembly assembly = result.Assembly;

 // Or get as bytes for storage
 byte[] assemblyBytes = result.AssemblyBytes;
}

CompilationError

Represents a compilation error or warning.

public class CompilationError
{
 public CompilationErrorTypes Type { get; } // Error, Warning, Info
 public string Id { get; } // e.g., "CS0001"
 public string Message { get; }
 public int Line { get; }
 public int Column { get; }
}

Reference Types

AssemblyReference

Reference to a .NET assembly.

// From file path
var fileRef = new AssemblyReference("path/to/assembly.dll");

// From loaded assembly
var loadedRef = new AssemblyReference(typeof(SomeClass).Assembly);

NuGetReference

Reference to a NuGet package.

var nugetRef = new NuGetReference
{
 PackageId = "Newtonsoft.Json",
 Version = "13.0.1"
};

Compiler Provider

Manages available compilers and provides access to them.

// Get registered compilers
IEnumerable<ICompiler> compilers = CompilerProvider.Compilers;

// Get compiler by extension
ICompiler csCompiler = CompilerProvider.GetCompiler(".cs");
ICompiler fsCompiler = CompilerProvider.GetCompiler(".fs");
ICompiler pyCompiler = CompilerProvider.GetCompiler(".py");

Compiler Implementations

Package Language Extension
Ecng.Compilation.Roslyn C# .cs
Ecng.Compilation.FSharp F# .fs
Ecng.Compilation.Python Python .py

Expression Formulas

Parse and evaluate mathematical expressions at runtime.

using Ecng.Compilation.Expressions;

// Parse expression
var formula = ExpressionHelper.Parse("(a + b) * 2");

// Get variables used
IEnumerable<string> vars = formula.Variables; // ["a", "b"]

// Evaluate with values
var values = new Dictionary<string, decimal>
{
 ["a"] = 10,
 ["b"] = 5
};
decimal result = formula.Calculate(values); // 30

Supported Operations

  • Arithmetic: +, -, *, /, %
  • Comparison: <, >, <=, >=, ==, !=
  • Logical: &&, ||, !
  • Functions: abs, sqrt, min, max, pow, etc.

Assembly Load Context

Manage assembly loading for isolation.

using Ecng.Compilation;

// Track loaded assemblies
var tracker = new AssemblyLoadContextTracker();

// Load assembly in isolated context
var context = tracker.CreateContext("MyPlugin");
Assembly asm = context.LoadFromAssemblyPath("plugin.dll");

// Unload when done
tracker.Unload("MyPlugin");

Compiler Cache

Cache compiled assemblies for reuse.

public interface ICompilerCache
{
 bool TryGet(string key, out byte[] assembly);
 void Set(string key, byte[] assembly);
 void Remove(string key);
 void Clear();
}

Usage Examples

Compile C# Code

var compiler = CompilerProvider.GetCompiler(".cs");

string code = @"
public class Calculator
{
 public int Add(int a, int b) => a + b;
}";

var result = await compiler.Compile(
 name: "Calculator",
 sources: new[] { code },
 refs: Array.Empty<(string, byte[])>());

if (!result.HasErrors)
{
 var type = result.Assembly.GetType("Calculator");
 var instance = Activator.CreateInstance(type);
 var method = type.GetMethod("Add");
 int sum = (int)method.Invoke(instance, new object[] { 2, 3 });
 Console.WriteLine(sum); // 5
}

Compile with References

var refs = new List<(string, byte[])>();

// Add reference
var asmBytes = File.ReadAllBytes("MyLibrary.dll");
refs.Add(("MyLibrary.dll", asmBytes));

var result = await compiler.Compile("MyCode", sources, refs);

NuGet

Install-Package Ecng.Compilation
Install-Package Ecng.Compilation.Roslyn # For C# support
Install-Package Ecng.Compilation.FSharp # For F# support
Install-Package Ecng.Compilation.Python # For Python support
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Ecng.Compilation:

Package Downloads
StockSharp.Algo

Trading algorithms. More info on web site https://stocksharp.com/store/

Ecng.Compilation.Roslyn

Ecng system framework

Ecng.Roslyn

Ecng system framework

Ecng.Compilation.Python

Ecng system framework

Ecng.Compilation.FSharp

Ecng system framework

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Ecng.Compilation:

Repository Stars
StockSharp/StockSharp
Algorithmic trading and quantitative trading open source platform to develop trading robots (stock markets, forex, crypto, bitcoins, and options).
Version Downloads Last Updated
1.0.316 0 6/18/2026
1.0.315 135 6/17/2026
1.0.314 298 6/14/2026
1.0.313 240 6/12/2026
1.0.312 217 6/9/2026
1.0.311 212 6/8/2026
1.0.310 340 6/2/2026
1.0.309 303 5/31/2026
1.0.308 374 5/15/2026
1.0.307 210 5/14/2026
1.0.306 300 5/6/2026
1.0.305 277 5/3/2026
1.0.304 312 4/30/2026
1.0.303 486 4/14/2026
1.0.302 1,177 3/17/2026
1.0.301 264 3/17/2026
1.0.300 282 3/15/2026
1.0.299 225 3/15/2026
1.0.298 515 3/10/2026
1.0.297 396 3/3/2026
Loading failed