public override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeDeclarationSyntax typeDeclaration)) { return; } Diagnostic diagnostic = context.Diagnostics[0]; Document document = context.Document; CodeAction codeAction = CodeAction.Create( ModifiersCodeFixRegistrator.GetRemoveModifierTitle(SyntaxKind.PartialKeyword), ct => { TypeDeclarationSyntax newTypeDeclaration = typeDeclaration.ReplaceNodes( typeDeclaration.Members.OfType <MethodDeclarationSyntax>().Where(f => f.Modifiers.Contains(SyntaxKind.PartialKeyword) && f.BodyOrExpressionBody() != null), (f, _) => f.RemoveModifier(SyntaxKind.PartialKeyword)); int count = newTypeDeclaration.Members.Count; for (int i = count - 1; i >= 0; i--) { if (newTypeDeclaration.Members[i] is MethodDeclarationSyntax method && method.Modifiers.Contains(SyntaxKind.PartialKeyword)) { newTypeDeclaration = SyntaxRefactorings.RemoveMember(newTypeDeclaration, method); } }