/// <summary> /// Compile code built up by using an ISourceWriter to a new assembly in memory /// </summary> /// <param name="write"></param> /// <returns></returns> public Assembly Generate(Action <ISourceWriter> write) { using (var writer = new SourceWriter()) { write(writer); return(Generate(writer.Code())); } }
public string GenerateCode(IServiceVariableSource services = null) { foreach (var generatedType in GeneratedTypes) { services?.StartNewType(); generatedType.ArrangeFrames(services); } var namespaces = GeneratedTypes .SelectMany(x => x.AllInjectedFields) .Select(x => x.ArgType.Namespace) .Concat(new string[] { typeof(Task).Namespace }) .Distinct().ToList(); var writer = new SourceWriter(); foreach (var ns in namespaces.OrderBy(x => x)) { writer.Write($"using {ns};"); } writer.BlankLine(); writer.Namespace(Generation.ApplicationNamespace); foreach (var @class in GeneratedTypes) { writer.WriteLine($"// START: {@class.TypeName}"); @class.Write(writer); writer.WriteLine($"// END: {@class.TypeName}"); writer.WriteLine(""); writer.WriteLine(""); } writer.FinishBlock(); var code = writer.Code(); attachSourceCodeToChains(code); return(code); }