public override SyntaxNode VisitAnonymousObjectMemberDeclarator( AnonymousObjectMemberDeclaratorSyntax node ) { var nameEquals = node.NameEquals; var expression = node.Expression; var identifier = expression as IdentifierNameSyntax; if ( nameEquals != null || identifier == null || !IsReference(identifier) || HasConflict(identifier, _variableDeclarator) ) { return(base.VisitAnonymousObjectMemberDeclarator(node)); } // Special case inlining into anonymous types to ensure that we keep property names: // // E.g. // int x = 42; // var a = new { x; }; // // Should become: // var a = new { x = 42; }; nameEquals = SyntaxFactory.NameEquals(identifier); expression = (ExpressionSyntax)Visit(expression); return(node.Update(nameEquals, expression) .WithAdditionalAnnotations(Simplifier.Annotation, Formatter.Annotation)); }
public override SyntaxNode?VisitAnonymousObjectMemberDeclarator(AnonymousObjectMemberDeclaratorSyntax node) { if (node.NameEquals == null && node.Expression is IdentifierNameSyntax identifier && _nonConflictReferences.Contains(identifier)) { // Special case inlining into anonymous types to ensure that we keep property names: // // E.g. // int x = 42; // var a = new { x; }; // // Should become: // var a = new { x = 42; }; return(node.Update(SyntaxFactory.NameEquals(identifier), (ExpressionSyntax)Visit(node.Expression))); } return(base.VisitAnonymousObjectMemberDeclarator(node)); }
public override SyntaxNode VisitAnonymousObjectMemberDeclarator(AnonymousObjectMemberDeclaratorSyntax node) { var nameEquals = node.NameEquals; var expression = node.Expression; var identifier = expression as IdentifierNameSyntax; if (nameEquals != null || identifier == null || !IsReference(identifier) || HasConflict(identifier, _variableDeclarator)) { return base.VisitAnonymousObjectMemberDeclarator(node); } // Special case inlining into anonymous types to ensure that we keep property names: // // E.g. // int x = 42; // var a = new { x; }; // // Should become: // var a = new { x = 42; }; nameEquals = SyntaxFactory.NameEquals(identifier); expression = (ExpressionSyntax)this.Visit(expression); return node.Update(nameEquals, expression).WithAdditionalAnnotations(Simplifier.Annotation, Formatter.Annotation); }