Table of Contents

Class ICompilerExtensions

Namespace
Ecng.Compilation
Assembly
Ecng.Compilation.dll

Provides extension methods for the ICompiler interface and compilation results.

public static class ICompilerExtensions
Inheritance
ICompilerExtensions
Inherited Members

Properties

RuntimePath

Gets the runtime directory path where the System.Object assembly is located.

public static string RuntimePath { get; }

Property Value

string

Methods

Compile(ICompiler, string, IEnumerable<string>, IEnumerable<string>, CancellationToken)

Compiles the provided source code using the specified compiler and references.

public static Task<CompilationResult> Compile(this ICompiler compiler, string name, IEnumerable<string> sources, IEnumerable<string> refs, CancellationToken cancellationToken = default)

Parameters

compiler ICompiler

The compiler instance.

name string

The name of the compilation unit.

sources IEnumerable<string>

The source code files as strings.

refs IEnumerable<string>

A collection of reference paths.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<CompilationResult>

A task representing the asynchronous compilation, containing the compilation result.

Compile(ICompiler, string, string, IEnumerable<string>, CancellationToken)

Compiles the provided source code using the specified compiler and references.

public static Task<CompilationResult> Compile(this ICompiler compiler, string name, string source, IEnumerable<string> refs, CancellationToken cancellationToken = default)

Parameters

compiler ICompiler

The compiler instance.

name string

The name of the compilation unit.

source string

The source code as a string.

refs IEnumerable<string>

A collection of reference paths.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<CompilationResult>

A task representing the asynchronous compilation, containing the compilation result.

ErrorsOnly(IEnumerable<CompilationError>)

Filters and returns only the errors (excluding warnings and info) from the collection of compilation errors.

public static IEnumerable<CompilationError> ErrorsOnly(this IEnumerable<CompilationError> errors)

Parameters

errors IEnumerable<CompilationError>

The collection of compilation errors to filter.

Returns

IEnumerable<CompilationError>

A filtered collection containing only errors.

HasErrors(CompilationResult)

Determines whether the given compilation result contains any errors.

public static bool HasErrors(this CompilationResult result)

Parameters

result CompilationResult

The compilation result to check.

Returns

bool

true if there are errors; otherwise, false.

HasErrors(IEnumerable<CompilationError>)

Determines whether the given collection of compilation errors contains any errors.

public static bool HasErrors(this IEnumerable<CompilationError> errors)

Parameters

errors IEnumerable<CompilationError>

The collection of compilation errors to check.

Returns

bool

true if there are errors; otherwise, false.

ThrowIfErrors(CompilationResult)

Throws an exception if the compilation result contains errors.

public static CompilationResult ThrowIfErrors(this CompilationResult res)

Parameters

res CompilationResult

The compilation result.

Returns

CompilationResult

The original compilation result if no errors are found.

ThrowIfErrors(IEnumerable<CompilationError>)

Throws an exception if the collection of compilation errors contains any errors.

public static IEnumerable<CompilationError> ThrowIfErrors(this IEnumerable<CompilationError> errors)

Parameters

errors IEnumerable<CompilationError>

The collection of compilation errors.

Returns

IEnumerable<CompilationError>

The original collection of errors if no errors are found.

ToError(Exception)

Converts an exception to a compilation error.

public static CompilationError ToError(this Exception ex)

Parameters

ex Exception

The exception to convert.

Returns

CompilationError

A new CompilationError instance representing the exception.

ToFullRuntimePath(string)

Combines the runtime directory path with the given assembly name.

public static string ToFullRuntimePath(this string assemblyName)

Parameters

assemblyName string

The name of the assembly file.

Returns

string

The full path to the assembly in the runtime directory.

ToRef(string)

Reads the file at the given path and returns its file name and binary content.

public static (string name, byte[] body) ToRef(this string path)

Parameters

path string

The path to the reference file.

Returns

(string name, byte[] body)

A tuple containing the file name and its binary content.

ToValidRefImages<TRef>(IEnumerable<TRef>, CancellationToken)

Asynchronously extracts valid reference images from the provided references.

public static ValueTask<IEnumerable<(string name, byte[] body)>> ToValidRefImages<TRef>(this IEnumerable<TRef> references, CancellationToken cancellationToken) where TRef : ICodeReference

Parameters

references IEnumerable<TRef>

The collection of code references.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

ValueTask<IEnumerable<(string name, byte[] body)>>

A task representing the asynchronous operation that returns an array of reference image tuples.

Type Parameters

TRef

The type of the code reference.