Beispiel #1
0
        /// <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)
        {
            var writer = new SourceWriter();

            write(writer);

            return(Generate(writer.Code()));
        }
        public string GenerateCode(ServiceGraph services = null)
        {
            foreach (var generatedType in GeneratedTypes)
            {
                if (generatedType.TypeName == "Microsoft_AspNetCore_Cors_Infrastructure_ICorsPolicyProvider_corsPolicyProvider")
                {
                    Debugger.Break();
                }
                generatedType.ArrangeFrames(services);
            }

            var namespaces = GeneratedTypes
                             .SelectMany(x => x.Args())
                             .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);
        }