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
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
compilerICompilerThe compiler instance.
namestringThe name of the compilation unit.
sourcesIEnumerable<string>The source code files as strings.
refsIEnumerable<string>A collection of reference paths.
cancellationTokenCancellationTokenA 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
compilerICompilerThe compiler instance.
namestringThe name of the compilation unit.
sourcestringThe source code as a string.
refsIEnumerable<string>A collection of reference paths.
cancellationTokenCancellationTokenA 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
errorsIEnumerable<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
resultCompilationResultThe compilation result to check.
Returns
- bool
trueif 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
errorsIEnumerable<CompilationError>The collection of compilation errors to check.
Returns
- bool
trueif there are errors; otherwise,false.
ThrowIfErrors(CompilationResult)
Throws an exception if the compilation result contains errors.
public static CompilationResult ThrowIfErrors(this CompilationResult res)
Parameters
resCompilationResultThe 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
errorsIEnumerable<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
exExceptionThe 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
assemblyNamestringThe 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
pathstringThe path to the reference file.
Returns
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
referencesIEnumerable<TRef>The collection of code references.
cancellationTokenCancellationTokenA 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
TRefThe type of the code reference.