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
- compilerICompiler
- The compiler instance. 
- namestring
- The name of the compilation unit. 
- sourcesIEnumerable<string>
- The source code files as strings. 
- refsIEnumerable<string>
- A collection of reference paths. 
- cancellationTokenCancellationToken
- 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
- compilerICompiler
- The compiler instance. 
- namestring
- The name of the compilation unit. 
- sourcestring
- The source code as a string. 
- refsIEnumerable<string>
- A collection of reference paths. 
- cancellationTokenCancellationToken
- 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
- 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
- resultCompilationResult
- The 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
- resCompilationResult
- 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
- 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
- exException
- 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
- assemblyNamestring
- 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
- pathstring
- The 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 : ICodeReferenceParameters
- referencesIEnumerable<TRef>
- The collection of code references. 
- cancellationTokenCancellationToken
- 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.