예제 #1
0
 public void VisitLambda(CodeLambdaExpression l)
 {
     if (l.Arguments.Length == 1)
     {
         l.Arguments[0].Accept(this);
     }
     else
     {
         writer.Write("(");
         var sep = "";
         foreach (var arg in l.Arguments)
         {
             writer.Write(sep);
             sep = ",";
             arg.Accept(this);
         }
         writer.Write(")");
     }
     writer.Write(" =>");
     if (l.Body != null)
     {
         writer.Write(" ");
         l.Body.Accept(this);
     }
     else
     {
         var sw = new CSharpStatementWriter(writer);
         sw.WriteStatements(l.Statements);
     }
 }
예제 #2
0
        public int VisitConstructor(CodeConstructor cons)
        {
            RenderCustomAttributes(cons);
            RenderMethodAttributes(cons.Attributes);
            writer.WriteName(type.Name);
            WriteMethodParameters(cons);
            if (cons.BaseConstructorArgs.Count > 0)
            {
                writer.WriteLine();
                ++writer.IndentLevel;
                writer.Write(": ");
                writer.Write("base");
                writer.Write("(");
                var sep = "";
                foreach (var e in cons.BaseConstructorArgs)
                {
                    writer.Write(sep);
                    sep = ", ";
                    e.Accept(expWriter);
                }
                writer.Write(")");
                --writer.IndentLevel;
            }
            if (cons.ChainedConstructorArgs.Count > 0)
            {
                writer.WriteLine();
                ++writer.IndentLevel;
                writer.Write(": ");
                writer.Write("this");
                writer.Write("(");
                var sep = "";
                foreach (var e in cons.ChainedConstructorArgs)
                {
                    writer.Write(sep);
                    sep = ", ";
                    e.Accept(expWriter);
                }
                writer.Write(")");
                --writer.IndentLevel;
            }

            var stmWriter = new CSharpStatementWriter(writer);

            stmWriter.WriteStatements(cons.Statements);
            writer.WriteLine();
            return(0);
        }
예제 #3
0
        public int VisitMethod(CodeMemberMethod method)
        {
            foreach (var comment in method.Comments)
            {
                writer.Write("//");
                writer.WriteLine(comment.Comment);
            }
            RenderCustomAttributes(method);
            RenderMethodAttributes(method.Attributes);
            var expWriter = new CSharpExpressionWriter(writer);

            expWriter.VisitTypeReference(method.ReturnType);
            writer.Write(" ");
            writer.WriteName(method.Name);
            WriteMethodParameters(method);

            var stmWriter = new CSharpStatementWriter(writer);

            stmWriter.WriteStatements(method.Statements);
            writer.WriteLine();
            return(0);
        }
예제 #4
0
        public int VisitProperty(CodeMemberProperty property)
        {
            foreach (var comment in property.Comments)
            {
                writer.Write("//");
                writer.WriteLine(comment.Comment);
            }
            RenderCustomAttributes(property);
            RenderMemberFieldAttributes(property.Attributes);
            var expWriter = new CSharpExpressionWriter(writer);

            expWriter.VisitTypeReference(property.PropertyType);
            writer.Write(" ");
            writer.WriteName(property.Name);
            writer.Write(" ");
            writer.Write("{");
            writer.WriteLine();
            ++writer.IndentLevel;
            writer.Write("get");

            var stmWriter = new CSharpStatementWriter(writer);

            stmWriter.WriteStatements(property.GetStatements);
            writer.WriteLine();

            if (property.SetStatements.Count > 0)
            {
                writer.Write("set");
                stmWriter = new CSharpStatementWriter(writer);
                stmWriter.WriteStatements(property.SetStatements);
                writer.WriteLine();
            }

            --writer.IndentLevel;
            writer.Write("}");
            writer.WriteLine();
            return(0);
        }
예제 #5
0
 internal void GenerateCodeFromStatement(CodeStatement csStmt, TextWriter writer, CodeGeneratorOptions codeGeneratorOptions)
 {
     this.writer = new IndentingTextWriter(writer);
     stmWriter   = new CSharpStatementWriter(this.writer);
     csStmt.Accept(stmWriter);
 }