public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) { ClassDeclarationSyntax processedNode = (ClassDeclarationSyntax)base.VisitClassDeclaration(node); if (node.Equals(this.baseTypeDeclaration)) { // Insert field in base type declaration ClassDeclarationSyntax newClassDeclaration = processedNode.AddMembers(this.newFieldDeclaration); return(newClassDeclaration); } return(processedNode); }
public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) { ClassDeclarationSyntax processedNode = (ClassDeclarationSyntax)base.VisitClassDeclaration(node); if (node.Equals(this.typeDeclaration)) { SyntaxTokenList getterModifiers = Syntax.TokenList(Syntax.Token(SyntaxKind.PublicKeyword)); if (isStatic) { getterModifiers = getterModifiers.Add(Syntax.Token(SyntaxKind.StaticKeyword)); } // Create property PropertyDeclarationSyntax propertyDeclaration = Syntax.PropertyDeclaration(this.fieldDeclaration.Declaration.Type, this.getterName) .WithModifiers(getterModifiers) .WithTrailingTrivia(Syntax.EndOfLine("")) .WithAccessorList( Syntax.AccessorList(Syntax.List <AccessorDeclarationSyntax>( Syntax.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithBody( Syntax.Block(Syntax.ReturnStatement(Syntax.IdentifierName(this.variableDeclarator.Identifier))) ), Syntax.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithBody( Syntax.Block( Syntax.ExpressionStatement( Syntax.BinaryExpression( SyntaxKind.AssignExpression, Syntax.IdentifierName(this.variableDeclarator.Identifier), Syntax.IdentifierName("value")) ) ) ) ))) .WithAdditionalAnnotations(CodeAnnotations.Formatting); ClassDeclarationSyntax newTypeDeclaration = processedNode.AddMembers(propertyDeclaration); return(newTypeDeclaration); } return(processedNode); }