ICompilerExtensions

Ecng.Compilation

Provides extension methods for the ICompiler interface and compilation results.

Propiedades

RuntimePath
public static string RuntimePath { get; }
value = ICompilerExtensions.RuntimePath

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

Métodos

Compile
public static Task<CompilationResult> Compile(ICompiler compiler, string name, string source, IEnumerable<string> refs, IFileSystem fileSystem, CancellationToken cancellationToken)
result = ICompilerExtensions.Compile(compiler, name, source, refs, fileSystem, cancellationToken)

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

compiler
The compiler instance.
name
The name of the compilation unit.
source
The source code as a string.
refs
A collection of reference paths.
fileSystem
The file system to use.
cancellationToken
A token to monitor for cancellation requests.

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

Compile
public static Task<CompilationResult> Compile(ICompiler compiler, string name, IEnumerable<string> sources, IEnumerable<string> refs, IFileSystem fileSystem, CancellationToken cancellationToken)
result = ICompilerExtensions.Compile(compiler, name, sources, refs, fileSystem, cancellationToken)

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

compiler
The compiler instance.
name
The name of the compilation unit.
sources
The source code files as strings.
refs
A collection of reference paths.
fileSystem
The file system to use.
cancellationToken
A token to monitor for cancellation requests.

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

ErrorsOnly
public static IEnumerable<CompilationError> ErrorsOnly(IEnumerable<CompilationError> errors)
result = ICompilerExtensions.ErrorsOnly(errors)

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

errors
The collection of compilation errors to filter.

Devuelve: A filtered collection containing only errors.

HasErrors
public static bool HasErrors(CompilationResult result)
result = ICompilerExtensions.HasErrors(result)

Determines whether the given compilation result contains any errors.

result
The compilation result to check.

Devuelve: true if there are errors; otherwise, false.

HasErrors
public static bool HasErrors(IEnumerable<CompilationError> errors)
result = ICompilerExtensions.HasErrors(errors)

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

errors
The collection of compilation errors to check.

Devuelve: true if there are errors; otherwise, false.

IsFSharp
public static bool IsFSharp(EventInfo evt)
result = ICompilerExtensions.IsFSharp(evt)

Determines whether the specified event is an F# event.

evt
The event information to check.

Devuelve: true if the event is an F# event; otherwise, false.

IsFSharpHandler
public static bool IsFSharpHandler(Type evtHandler)
result = ICompilerExtensions.IsFSharpHandler(evtHandler)

Determines whether the specified event handler type is an F# handler.

evtHandler
The event handler type to check.

Devuelve: true if the type is an F# handler; otherwise, false.

ThrowIfErrors
public static CompilationResult ThrowIfErrors(CompilationResult res)
result = ICompilerExtensions.ThrowIfErrors(res)

Throws an exception if the compilation result contains errors.

res
The compilation result.

Devuelve: The original compilation result if no errors are found.

ThrowIfErrors
public static IEnumerable<CompilationError> ThrowIfErrors(IEnumerable<CompilationError> errors)
result = ICompilerExtensions.ThrowIfErrors(errors)

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

errors
The collection of compilation errors.

Devuelve: The original collection of errors if no errors are found.

ToError
public static CompilationError ToError(Exception ex)
result = ICompilerExtensions.ToError(ex)

Converts an exception to a compilation error.

ex
The exception to convert.

Devuelve: A new CompilationError instance representing the exception.

ToFullRuntimePath
public static string ToFullRuntimePath(string assemblyName)
result = ICompilerExtensions.ToFullRuntimePath(assemblyName)

Combines the runtime directory path with the given assembly name.

assemblyName
The name of the assembly file.

Devuelve: The full path to the assembly in the runtime directory.

ToRef
public static ValueTuple<string, byte[]> ToRef(string path, IFileSystem fileSystem)
result = ICompilerExtensions.ToRef(path, fileSystem)

Reads the file at the given path and returns its file name and binary content. The content is cached per file system and re-read only once the file's last write time or length changes, so the same image instance is handed out to repeated compilations.

path
The path to the reference file.
fileSystem
The file system to use.

Devuelve: A tuple containing the file name and its binary content.

ToValidRefImages``1
public static ValueTask<IEnumerable<ValueTuple<string, byte[]>>> ToValidRefImages<TRef>(IEnumerable<TRef> references, CancellationToken cancellationToken)
result = ICompilerExtensions.ToValidRefImages(references, cancellationToken)

Asynchronously extracts valid reference images from the provided references.

references
The collection of code references.
cancellationToken
A token to monitor for cancellation requests.

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