public static async Task <T> CompileAndRun <T>(this IAnalyser analyser, string type, string methodName, BindingFlags methodFlags, object instance = null, params object[] parameters) { if (analyser is null) { throw new ArgumentNullException(nameof(analyser)); } if (type is null) { throw new ArgumentNullException(nameof(type)); } if (methodName is null) { throw new ArgumentNullException(nameof(methodName)); } CompilerResult compiled = await analyser.CompileAsync(); if (!compiled.Success) { return(default);
public static CompilerResult ToCompilerResult(this Compilation compilation) { if (compilation is null) { throw new ArgumentNullException(nameof(compilation)); } var outputCodeStream = new MemoryStream(); EmitResult result = compilation.Emit(outputCodeStream); var compiled = outputCodeStream.ToArray(); if (!result.Success || compiled.Length == 0) { return(CompilerResult.FromFail(result.Diagnostics)); } else { return(CompilerResult.FromSuccess(result.Diagnostics, compiled)); } }