Exemplo n.º 1
0
 public static void WriteMethodParameters(List <CodeParameterDeclarationExpression> parameters, IndentingTextWriter writer)
 {
     writer.Write("(");
     if (parameters.Count > 4)
     {
         // Poor man's pretty printer
         ++writer.IndentLevel;
         writer.WriteLine();
         for (int i = 0; i < parameters.Count; ++i)
         {
             WriteParameter(parameters[i], writer);
             if (i < parameters.Count - 1)
             {
                 writer.WriteLine(",");
             }
         }
         --writer.IndentLevel;
     }
     else
     {
         var sep = "";
         foreach (var param in parameters)
         {
             writer.Write(sep);
             sep = ", ";
             WriteParameter(param, writer);
         }
     }
     writer.WriteName(")");
 }
Exemplo n.º 2
0
        public int VisitField(CodeMemberField field)
        {
            RenderMemberFieldAttributes(field.Attributes);
            var expWriter = new CSharpExpressionWriter(writer);

            expWriter.VisitTypeReference(field.FieldType);
            writer.Write(" ");
            writer.WriteName(field.FieldName);
            if (field.InitExpression != null)
            {
                writer.Write(" = ");
                field.InitExpression.Accept(expWriter);
            }
            writer.Write(";");
            writer.WriteLine();
            return(0);
        }
Exemplo n.º 3
0
 private void WriteCatchClause(CodeCatchClause clause)
 {
     writer.Write(" ");
     writer.Write("catch");
     if (clause.CatchExceptionType != null)
     {
         writer.Write(" (");
         expWriter.VisitTypeReference(clause.CatchExceptionType);
         if (!string.IsNullOrEmpty(clause.LocalName))
         {
             writer.Write(" ");
             writer.WriteName(clause.LocalName);
         }
         writer.Write(")");
     }
     WriteStatements(clause.Statements);
 }
Exemplo n.º 4
0
 public int VisitVariableDeclaration(CodeVariableDeclarationStatement decl)
 {
     expWriter.VisitTypeReference(decl.Type);
     writer.Write(" ");
     writer.WriteName(decl.Name);
     if (decl.InitExpression != null)
     {
         writer.Write(" = ");
         decl.InitExpression.Accept(expWriter);
     }
     writer.WriteLine(";");
     return(0);
 }
Exemplo n.º 5
0
 public void Write(CodeCompileUnit unit)
 {
     foreach (var n in unit.Namespaces)
     {
         foreach (var comment in n.Comments)
         {
             writer.Write("//");
             writer.Write(comment.Comment);
             writer.WriteLine();
         }
         if (!string.IsNullOrEmpty(n.Name))
         {
             writer.Write("namespace");
             writer.WriteName(" ");
             writer.WriteDottedName(n.Name);
             writer.WriteLine(" {");
             ++writer.IndentLevel;
         }
         foreach (var imp in n.Imports)
         {
             writer.WriteLine();
             writer.Write("using");
             writer.Write(" ");
             writer.WriteDottedName(imp.Namespace);
             writer.WriteLine(";");
         }
         foreach (var type in n.Types)
         {
             writer.WriteLine();
             var tw = new CSharpTypeWriter(type, writer);
             type.Accept(tw);
         }
         if (!string.IsNullOrEmpty(n.Name))
         {
             --writer.IndentLevel;
             writer.WriteLine("}");
         }
     }
 }
Exemplo n.º 6
0
 public void VisitFieldReference(CodeFieldReferenceExpression field)
 {
     Write(field.Expression, PrecPostfix, false);
     writer.Write(".");
     writer.WriteName(field.FieldName);
 }