Adding an attribute to a class after the documentation comment trivia I am trying to turn

namespace DevComponents.WpfEditors.Primitives
{
    /// &lt;summary&gt;
    /// Interaction logic for EditorFreeTextButton.xaml
    /// &lt;/summary&gt;
    public partial class EditorFreeTextButton : EditorButton
    {
        public EditorFreeTextButton()
        {
            InitializeComponent();
        }
    }
}


into

namespace DevComponents.WpfEditors.Primitives
{
    /// &lt;summary&gt;
    /// Interaction logic for EditorFreeTextButton.xaml
    /// &lt;/summary&gt;
    [System.Reflection.Obfuscation(Exclude = true)]
    public partial class EditorFreeTextButton : EditorButton
    {
        public EditorFreeTextButton()
        {
            InitializeComponent();
        }
    }
}


through Roslyn. I have the following code that works 

private static SyntaxNode AddAnnotation(ClassDeclarationSyntax classNode, SyntaxNode rootNode)
{
    var name = SyntaxFactory.ParseName("System.Reflection.Obfuscation");
    var arguments = SyntaxFactory.ParseAttributeArgumentList("(Exclude = true)");
    var attribute = SyntaxFactory.Attribute(name, arguments);
    var leadingTrivia = classNode.GetLeadingTrivia();
    var whitespace = leadingTrivia.LastOrDefault(x =&gt; x.Kind() == SyntaxKind.WhitespaceTrivia);

    var attributeList = SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(attribute))
        .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);
    var newClassNode = classNode.WithoutLeadingTrivia()
        .WithLeadingTrivia(whitespace)
        .AddAttributeLists(attributeList)
        .WithLeadingTrivia(leadingTrivia);

    rootNode = rootNode.ReplaceNode(classNode, newClassNode);
    return rootNode;
}


However I feel like I am coding in circles to get all the leading Trivia right. 

Is there a easier way to insert an attribute to be after the SingleLineDocumentationCommentTrivia and be formatted correctly with the correct leading whitespace trivia?
Look into the WithAnnotation(Formatter.Annotation) member.  This should create a new node with the correct leading indentation.

var newClassNode = classNode.AddAttributeLists(attributeList)
                            .WithAnnotation(Formatter.Annotation)