Example #1
0
 private void FormatBody(CSharpFormatterContext context)
 {
     var @out = context.Out;
     if (!String.IsNullOrEmpty(context.Doc.Namespace))
     {
         @out.WriteLine("namespace {0}", context.Doc.Namespace.Replace('/', '.'));
         @out.WriteLine("{");
         context.Indent();
     }
     var leading = true;
     foreach (var def in context.Doc.Definitions)
     {
         if (leading)
         {
             leading = false;
         }
         else
         {
             context.Out.WriteLine();
         }
         def.Format(context);
     }
     if (!String.IsNullOrEmpty(context.Doc.Namespace))
     {
         context.Unindent();
         @out.WriteLine("}");
     }
 }
Example #2
0
 public override bool Format(Document doc, string outDir)
 {
     try
     {
         var context = new CSharpFormatterContext()
         {
             Doc = doc,
             Target = Path.Combine(outDir, doc.BaseName + Extension)
         };
         using (var writer = new StreamWriter(context.Target, false, Encoding.UTF8))
         {
             context.Out = writer;
             FormatHead(context);
             FormatBody(context);
             writer.Flush();
         }
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.Message);
         return false;
     }
     return true;
 }
Example #3
0
        private void FormatHead(CSharpFormatterContext context)
        {
            var @out = context.Out;
            @out.WriteLine("// auto-generated by x2clr xpiler");
            @out.WriteLine();
            @out.WriteLine("using System;");
            @out.WriteLine("using System.Collections.Generic;");
            @out.WriteLine("using System.Text;");
            @out.WriteLine();
            @out.WriteLine("using x2;");
            @out.WriteLine();

            foreach (var reference in context.Doc.References)
            {
                reference.Format(context);
            }
        }