public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var syntaxTree = await context.Document.GetRequiredSyntaxTreeAsync(context.CancellationToken).ConfigureAwait(false); var syntaxNode = Location.Create(syntaxTree, context.Span).FindNode(context.CancellationToken); if (_syntaxFacts.GetModifiers(syntaxNode) != default) { RegisterCodeFix(context, AnalyzersResources.Order_modifiers, nameof(AnalyzersResources.Order_modifiers)); } }
protected void CheckModifiers( SyntaxTreeAnalysisContext context, Dictionary <int, int> preferredOrder, ReportDiagnostic severity, SyntaxNode memberDeclaration) { var modifiers = _syntaxFacts.GetModifiers(memberDeclaration); if (!AbstractOrderModifiersHelpers.IsOrdered(preferredOrder, modifiers)) { if (severity.WithDefaultSeverity(DiagnosticSeverity.Hidden) == ReportDiagnostic.Hidden) { // If the severity is hidden, put the marker on all the modifiers so that the // user can bring up the fix anywhere in the modifier list. context.ReportDiagnostic( Diagnostic.Create(Descriptor, context.Tree.GetLocation( TextSpan.FromBounds(modifiers.First().SpanStart, modifiers.Last().Span.End)))); } else { // If the Severity is not hidden, then just put the user visible portion on the // first token. That way we don't context.ReportDiagnostic( DiagnosticHelper.Create(Descriptor, modifiers.First().GetLocation(), severity, additionalLocations: null, properties: null)); } } }