Just some extensions for @SLaks answer. You need to expand CSharpSyntaxRewriterand override the method VisitTrivia. And here you need to check the Kindlittle things. Depending on your needs, you should filter single and multi-line comments:
trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia)
And return default(SyntaxTrivia)to remove them from the tree.
source
share