Ejemplo n.º 1
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            if (!context.Document.SupportsSyntaxTree)
            {
                return;
            }

            var syntaxRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var syntaxTree = syntaxRoot.SyntaxTree;

            /// This only disables codefixes when different versions are loaded
            /// In case of analyzers, <see cref="SonarAnalysisContext.IsAnalysisDisabled"/> is sufficient, because Roslyn only
            /// creates a single instance from each assembly-version, so we can disable the VSIX analyzers
            /// In case of code fix providers Roslyn creates multiple instances of the code fix providers. Which means that
            /// we can only disable one of them if they are created from different assembly-versions.
            /// If the VSIX and the Nuget has the same version, then code fixes show up multiple times, this ticket will fix
            /// this problem: https://github.com/dotnet/roslyn/issues/4030
            if (SonarAnalysisContext.IsAnalysisDisabled(syntaxTree))
            {
                return;
            }

            await RegisterCodeFixesAsync(syntaxRoot, context).ConfigureAwait(false);
        }