示例#1
0
        public void advanced_usages()
        {
            // SAMPLE: SourceWriterAdvanced
            var writer = new SourceWriter();

            // Add "using [namespace]; statements
            writer.UsingNamespace(typeof(Console).Namespace);
            writer.UsingNamespace <IOperation>();

            writer.Namespace("GeneratedCode");
            // Write new classes and code within the namespace
            writer.FinishBlock();


            // Helper to write using blocks in C# code
            writer.UsingBlock("var conn = new SqlConnection()", w =>
            {
                w.Write("conn.Open();");
                // other statements
            });



            // Write a comment text into the code at the correct indention
            // level
            writer.WriteComment("Some message");


            // Start the declaration of a new public class named "MyClass"
            // that implements the IDisposable interface
            writer.StartClass("MyClass", typeof(IDisposable));
            // ENDSAMPLE
        }
        public void write_using_by_type()
        {
            var writer = new SourceWriter();

            writer.UsingNamespace <ISourceWriter>();
            var lines = writer.Code().ReadLines().ToArray();

            lines[0].Should().Be($"using {typeof(ISourceWriter).Namespace};");
        }
示例#3
0
        public string GenerateCode(IGenerationConfig generation)
        {
            beforeGeneratingCode();

            var writer = new SourceWriter();

            writer.UsingNamespace <Task>();
            writer.BlankLine();

            writer.Namespace(generation.ApplicationNamespace);

            foreach (var chain in chains)
            {
                var generationModel = chain.ToGenerationModel(generation);


                // TODO -- figure out how to get the source code for each handler
                writer.WriteLine($"// START: {chain.TypeName}");

                HandlerSourceWriter.Write(generationModel, writer);
                writer.WriteLine($"// END: {chain.TypeName}");

                writer.WriteLine("");
                writer.WriteLine("");
            }

            writer.FinishBlock();


            var code = writer.Code();

            attachSourceCodeToChains(code);


            return(code);
        }