Exemple #1
0
        private void FormatBody(CSharpFormatterContext context)
        {
            var o = context.Writer;

            if (!String.IsNullOrEmpty(context.Unit.Namespace))
            {
                o.WriteLine("namespace {0}", context.Unit.Namespace.Replace('/', '.'));
                o.WriteLine("{");
                context.Indent();
            }
            var leading = true;

            foreach (var def in context.Unit.Definitions)
            {
                if (leading)
                {
                    leading = false;
                }
                else
                {
                    context.NewLine();
                }
                def.Format(context);
            }
            if (!String.IsNullOrEmpty(context.Unit.Namespace))
            {
                context.Unindent();
                o.WriteLine("}");
            }
        }
Exemple #2
0
        private void FormatHead(CSharpFormatterContext context)
        {
            var o = context.Writer;

            o.WriteLine("// auto-generated by x2net.xpiler");
            o.WriteLine();
            o.WriteLine("using System;");
            o.WriteLine("using System.Collections.Generic;");
            o.WriteLine("using System.Text;");
            o.WriteLine();
            o.WriteLine("using x2net;");
            o.WriteLine();

            foreach (var reference in context.Unit.References)
            {
                reference.Format(context);
            }
        }
Exemple #3
0
 public override bool Format(Unit unit, string outDir)
 {
     try
     {
         var context = new CSharpFormatterContext()
         {
             Unit   = unit,
             Target = Path.Combine(outDir, unit.BaseName + Extension)
         };
         using (var writer = new StreamWriter(new FileStream(context.Target, FileMode.Create)))
         {
             context.Writer = writer;
             FormatHead(context);
             FormatBody(context);
             writer.Flush();
         }
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.Message);
         return(false);
     }
     return(true);
 }