Skip to content

How to write codefix that adds an argument to method call? #69185

Closed Answered by miroslav77
miroslav77 asked this question in Q&A
Discussion options

You must be logged in to vote

I think I did it. It looks like this:

public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
    context.RegisterCodeFix(
        CodeAction.Create(
            title: "Add DuplicatePropertyNameHandling.None",
            createChangedDocument: c => AddDuplicatePropertyNameHandlingNoneAsync(context.Document, context.Span, c),
            equivalenceKey: "AddDuplicatePropertyNameHandlingNone"),
        context.Diagnostics);

    return Task.CompletedTask;
}

        private async Task<Document> AddDuplicatePropertyNameHandlingNoneAsync(Document document, TextSpan span, CancellationToken cancellationToken)
{
    var root = await document.GetSyntaxRootAsync(cancellation…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@miroslav77
Comment options

Answer selected by miroslav77
@sharwell
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Question Resolution-Answered The question has been answered
3 participants