예제 #1
0
        public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            string nodeString = node.ToFullString();

            string[] nodeLines      = nodeString.Split(NewlineSeparator, StringSplitOptions.RemoveEmptyEntries);
            bool     anyLineTooLong = nodeLines.Any(x => x.Length > MaxLengthOfLine);

            if (!anyLineTooLong)
            {
                return(base.VisitFieldDeclaration(node));
            }

            SyntaxToken firstEqualsToken = node.DescendantTokens().FirstOrDefault(x => x.Kind() is SyntaxKind.EqualsToken);

            if (firstEqualsToken.IsKind(SyntaxKind.None))
            {
                return(base.VisitFieldDeclaration(node));
            }

            SyntaxTrivia           newLeadingTrivia = GetNewTrivia(nodeLines);
            SyntaxToken            newEqualsToken   = FormatEqualsOrArrowTokenWhitespace(firstEqualsToken, newLeadingTrivia);
            FieldDeclarationSyntax newNode          = node.ReplaceToken(firstEqualsToken, newEqualsToken);

            return(base.VisitFieldDeclaration(newNode));
        }