コード例 #1
0
        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);
        }