Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fixer for CA2200 #2873

Merged
merged 2 commits into from Sep 30, 2019
Merged

Add a fixer for CA2200 #2873

merged 2 commits into from Sep 30, 2019

Conversation

goyzhang
Copy link
Contributor

@goyzhang goyzhang commented Sep 29, 2019

Replace throw e; to throw;
Reference #692

var diagnostic = context.Diagnostics.First();
var diagnosticSpan = diagnostic.Location.SourceSpan;

var nodeToReplace = root.FindNode(diagnosticSpan);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments:

  1. You don't need to get the first diagnostic or use it's span
  2. Please add a null check for nodeToReplace
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
            var nodeToReplace = root.FindNode(context.Span);
            if (nodeToReplace == null)
            {
                return;
            }

            context.RegisterCodeFix(
                CodeAction.Create(...),
                context.Diagnostics);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, Ok, I just got it from the boilerplate https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix and it does the job as well. I will modify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants