Code/Dependencies/Extensions/DotNetGraph/DotGraphExtensions.cs
using System.IO;
using System.Threading.Tasks;
using Nodebox.Dependencies.DotNetGraph.Compilation;
using Nodebox.Dependencies.DotNetGraph.Core;
namespace Nodebox.Dependencies.Extensions;
public static class DotGraphExtensions {
extension(DotGraph dotGraph) {
public void Compile(CompilationContext context) => dotGraph.CompileAsync(context).GetAwaiter().GetResult();
public async Task<string> CompileToStringAsync(CompilationOptions options) {
using var writer = new StringWriter();
var context = new CompilationContext(writer, options);
await dotGraph.CompileAsync(context);
var result = writer.GetStringBuilder().ToString();
return result;
}
public string CompileToString(CompilationOptions options) => dotGraph.CompileToStringAsync(options).GetAwaiter().GetResult();
}
}