Inheritance: ICodeExpressionVisitor
Beispiel #1
0
        public int VisitTypeDefinition(CodeTypeDeclaration type)
        {
            var oldType = this.type;

            this.type = type;
            var expWriter = new CSharpExpressionWriter(writer);

            foreach (var stm in type.Comments)
            {
                writer.Write("//");
                writer.WriteLine(stm.Comment);
            }
            RenderTypeMemberAttributes(type.Attributes);
            writer.Write("class");
            writer.Write(" ");
            writer.WriteName(type.Name);

            if (type.BaseTypes.Count > 0)
            {
                writer.WriteLine();
                ++writer.IndentLevel;
                writer.Write(": ");
                var sepStr = "";
                foreach (var bt in type.BaseTypes)
                {
                    writer.Write(sepStr);
                    sepStr = ", ";
                    expWriter.VisitTypeReference(bt);
                }
                --writer.IndentLevel;
            }
            writer.Write(" ");
            writer.Write("{");
            writer.WriteLine();
            ++writer.IndentLevel;
            bool sep = true;

            foreach (var m in type.Members)
            {
                if (sep)
                {
                    writer.WriteLine();
                }
                sep = true;
                m.Accept(this);
            }
            --writer.IndentLevel;
            writer.Write("}");
            writer.WriteLine();
            this.type = oldType;
            return(0);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
0
        private void WriteParameter(CodeParameterDeclarationExpression param)
        {
            var expType = new CSharpExpressionWriter(writer);

            if (param.IsVarargs)
            {
                writer.Write("params");
                writer.Write(" ");
                writer.Write("object");
                writer.Write(" [] ");
                writer.WriteName(param.ParameterName);
            }
            else
            {
                expType.VisitTypeReference(param.ParameterType);
                writer.Write(" ");
                writer.WriteName(param.ParameterName);
                if (param.DefaultValue != null)
                {
                    writer.Write(" = ");
                    param.DefaultValue.Accept(expType);
                }
            }
        }
Beispiel #6
0
 public CSharpStatementWriter(IndentingTextWriter writer)
 {
     this.writer    = writer;
     this.expWriter = new CSharpExpressionWriter(writer);
 }
Beispiel #7
0
 public CSharpTypeWriter(CodeTypeDeclaration type, IndentingTextWriter writer)
 {
     this.type      = type;
     this.writer    = writer;
     this.expWriter = new CSharpExpressionWriter(writer);
 }