public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); PropertyDeclarationSyntax property = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <PropertyDeclarationSyntax>(); if (property == null) { return; } foreach (Diagnostic diagnostic in context.Diagnostics) { switch (diagnostic.Id) { case DiagnosticIdentifiers.UseAutoImplementedProperty: { CodeAction codeAction = CodeAction.Create( "Use auto-property", cancellationToken => UseAutoImplementedPropertyRefactoring.RefactorAsync(context.Document, property, cancellationToken), diagnostic.Id + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, diagnostic); break; } } } }
private void AnalyzePropertyDeclaration(SyntaxNodeAnalysisContext context) { var property = (PropertyDeclarationSyntax)context.Node; UseAutoImplementedPropertyRefactoring.Analyze(context, property); }