public static ClassDeclarationSyntax StripAccessModifiers(ClassDeclarationSyntax classDeclarationSyntax) { if (classDeclarationSyntax.Modifiers.Count == 0) { return(classDeclarationSyntax); } var modifier = classDeclarationSyntax.FirstAccModifier(); while (modifier.HasValue) { classDeclarationSyntax = classDeclarationSyntax.RemoveNode(modifier.Value.Parent, SyntaxRemoveOptions.KeepNoTrivia); modifier = classDeclarationSyntax.FirstAccModifier(); } return(classDeclarationSyntax); }