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
compiler
ICompilerThe compiler instance.
name
stringThe name of the compilation unit.
sources
IEnumerable<string>The source code files as strings.
refs
IEnumerable<string>A collection of reference paths.
cancellationToken
CancellationTokenA 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
ICompilerThe compiler instance.
name
stringThe name of the compilation unit.
source
stringThe source code as a string.
refs
IEnumerable<string>A collection of reference paths.
cancellationToken
CancellationTokenA 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
CompilationResultThe 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
CompilationResultThe 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
ExceptionThe 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
stringThe 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
stringThe 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
references
IEnumerable<TRef>The collection of code references.
cancellationToken
CancellationTokenA 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.