InterfaceMethodsShouldBeCallableByChildTypesAnalyzer

We found 9 examples in language CSharp for this search. You will see 45 fragments of code.
        #region Verifiers

        protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesAnalyzer();
        }

        protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesAnalyzer();
        }

        private static DiagnosticResult CSharpResult(int line, int column, string className, string methodName)
        {
            return GetCSharpResultAt(line, column, InterfaceMethodsShouldBeCallableByChildTypesAnalyzer.Rule, className, methodName);
        }

        private static DiagnosticResult BasicResult(int line, int column, string className, string methodName)
        {
            return GetBasicResultAt(line, column, InterfaceMethodsShouldBeCallableByChildTypesAnalyzer.Rule, className, methodName);
        }


        public override FixAllProvider GetFixAllProvider()
        {
            return WellKnownFixAllProviders.BatchFixer;
        }

        public async override Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
            SyntaxNode nodeToFix = root.FindNode(context.Span);
            if (nodeToFix == null)
            {
                return;
            }

            var methodSymbol = semanticModel.GetDeclaredSymbol(nodeToFix, context.CancellationToken) as IMethodSymbol;
            if (methodSymbol == null)
            {
                return;
            }

            SyntaxGenerator generator = SyntaxGenerator.GetGenerator(context.Document);
            SyntaxNode declaration = generator.GetDeclaration(nodeToFix);
            if (declaration == null)
            {
                return;
            }

            IMethodSymbol candidateToIncreaseVisibility = GetExistingNonVisibleAlternate(methodSymbol);
            if (candidateToIncreaseVisibility != null)
            {
                ISymbol symbolToChange = candidateToIncreaseVisibility.IsAccessorMethod() ? candidateToIncreaseVisibility.AssociatedSymbol : candidateToIncreaseVisibility;
                if (symbolToChange != null)
                {
                    string title = string.Format(MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix1, symbolToChange.Name);

                    context.RegisterCodeFix(new MyCodeAction(title,
                         async ct => await MakeProtected(context.Document, symbolToChange, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix1),
                    context.Diagnostics);
                }
            }
            else
            {
                ISymbol symbolToChange = methodSymbol.IsAccessorMethod() ? methodSymbol.AssociatedSymbol : methodSymbol;
                if (symbolToChange != null)
                {
                    string title = string.Format(MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix2, symbolToChange.Name);

                    context.RegisterCodeFix(new MyCodeAction(title,
                         async ct => await ChangeToPublicInterfaceImplementation(context.Document, symbolToChange, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix2),
                    context.Diagnostics);
                }
            }

            context.RegisterCodeFix(new MyCodeAction(string.Format(MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3, methodSymbol.ContainingType.Name),
                     async ct => await MakeContainingTypeSealed(context.Document, methodSymbol, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftApiDesignGuidelinesAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3),
                context.Diagnostics);
        }

        private static IMethodSymbol GetExistingNonVisibleAlternate(IMethodSymbol methodSymbol)
        {
            foreach (IMethodSymbol interfaceMethod in methodSymbol.ExplicitInterfaceImplementations)
            {
                foreach (INamedTypeSymbol type in methodSymbol.ContainingType.GetBaseTypesAndThis())
                {
                    IMethodSymbol candidate = type.GetMembers(interfaceMethod.Name).OfType<IMethodSymbol>().FirstOrDefault(m => !m.Equals(methodSymbol));
                    if (candidate != null)
                    {
                        return candidate;
                    }
                }
            }

            return null;
        }

        private async Task<Document> MakeProtected(Document document, ISymbol symbolToChange, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                docEditor.SetAccessibility(declaration, Accessibility.Protected);
            }, cancellationToken).ConfigureAwait(false);

            return editor.GetChangedDocuments().First();
        }

        private async Task<Document> ChangeToPublicInterfaceImplementation(Document document, ISymbol symbolToChange, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            IEnumerable<ISymbol> explicitImplementations = GetExplicitImplementations(symbolToChange);
            if (explicitImplementations == null)
            {
                return document;
            }

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                SyntaxNode newDeclaration = declaration;
                foreach (ISymbol implementedMember in explicitImplementations)
                {
                    SyntaxNode interfaceTypeNode = docEditor.Generator.TypeExpression(implementedMember.ContainingType);
                    newDeclaration = docEditor.Generator.AsPublicInterfaceImplementation(newDeclaration, interfaceTypeNode);
                }

                docEditor.ReplaceNode(declaration, newDeclaration);
            }, cancellationToken).ConfigureAwait(false);

            return editor.GetChangedDocuments().First();
        }

        private static IEnumerable<ISymbol> GetExplicitImplementations(ISymbol symbol)
        {
            if (symbol == null)
            {
                return null;
            }

            switch (symbol.Kind)
            {
                case SymbolKind.Method:
                    return ((IMethodSymbol)symbol).ExplicitInterfaceImplementations;

                case SymbolKind.Event:
                    return ((IEventSymbol)symbol).ExplicitInterfaceImplementations;

                case SymbolKind.Property:
                    return ((IPropertySymbol)symbol).ExplicitInterfaceImplementations;

                default:
                    return null;
            }
        }


        public sealed override void Initialize(AnalysisContext analysisContext) =>
            analysisContext.RegisterCodeBlockAction(AnalyzeCodeBlock);

        protected abstract bool ShouldExcludeCodeBlock(SyntaxNode codeBlock);

        private void AnalyzeCodeBlock(CodeBlockAnalysisContext context)
        {
            if (context.OwningSymbol.Kind != SymbolKind.Method)
            {
                return;
            }

            var method = (IMethodSymbol)context.OwningSymbol;

            // We are only interested in private explicit interface implementations within a public non-sealed type.
            if (method.ExplicitInterfaceImplementations.Length == 0 ||
                method.GetResultantVisibility() != SymbolVisibility.Private ||
                method.ContainingType.IsSealed ||
                method.ContainingType.GetResultantVisibility() != SymbolVisibility.Public)
            {
                return;
            }

            // Avoid false reports from simple explicit implementations where the deriving type is not expected to access the base implementation.
            if (ShouldExcludeCodeBlock(context.CodeBlock))
            {
                return;
            }

            var hasPublicInterfaceImplementation = false;
            foreach (var interfaceMethod in method.ExplicitInterfaceImplementations)
            {
                // If any one of the explicitly implemented interface methods has a visible alternate, then effectively, they all do.
                if (HasVisibleAlternate(method.ContainingType, interfaceMethod, context.SemanticModel.Compilation))
                {
                    return;
                }

                hasPublicInterfaceImplementation = hasPublicInterfaceImplementation ||
                    interfaceMethod.ContainingType.GetResultantVisibility() == SymbolVisibility.Public;
            }

            // Even if none of the interface methods have alternates, there's only an issue if at least one of the interfaces is public.
            if (hasPublicInterfaceImplementation)
            {
                ReportDiagnostic(context, method.ContainingType.Name, method.Name);
            }
        }

        private static bool HasVisibleAlternate(INamedTypeSymbol namedType, IMethodSymbol interfaceMethod, Compilation compilation)
        {
            foreach (var type in namedType.GetBaseTypesAndThis())
            {
                foreach (var method in type.GetMembers(interfaceMethod.Name).OfType<IMethodSymbol>())
                {
                    if (method.GetResultantVisibility() == SymbolVisibility.Public)
                    {
                        return true;
                    }
                }
            }

            // This rule does not report a violation for an explicit implementation of IDisposable.Dispose when an externally visible Close() or System.IDisposable.Dispose(Boolean) method is provided.
            return interfaceMethod.Name.Equals("Dispose") &&
                interfaceMethod.ContainingType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat).Equals("System.IDisposable") &&
                namedType.GetBaseTypesAndThis().Any(t =>
                    t.GetMembers("Close").OfType<IMethodSymbol>().Any(m =>
                        m.GetResultantVisibility() == SymbolVisibility.Public));
        }

        private static void ReportDiagnostic(CodeBlockAnalysisContext context, params object[] messageArgs)
        {
            var diagnostic = Diagnostic.Create(Rule, context.OwningSymbol.Locations[0], messageArgs);
            context.ReportDiagnostic(diagnostic);
        }


        public sealed override void Initialize(AnalysisContext context)
        {
            context.EnableConcurrentExecution();
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

            context.RegisterCompilationStartAction(compilationContext =>
            {
                if (compilationContext.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemIDisposable, out var iDisposableTypeSymbol))
                {
                    compilationContext.RegisterOperationBlockAction(operationBlockContext => AnalyzeOperationBlock(operationBlockContext, iDisposableTypeSymbol));
                }
            });
        }

        private static bool ShouldExcludeOperationBlock(ImmutableArray<IOperation> operationBlocks)
        {
            if (operationBlocks != null && operationBlocks.Length == 1)
            {

                // Analyze IBlockOperation blocks.
                if (operationBlocks[0] is not IBlockOperation block)
                {
                    return true;
                }

                var explicitOperations = block.Operations.WithoutFullyImplicitOperations();
                if (explicitOperations.IsEmpty)
                {
                    // Empty body.
                    return true;
                }

                if (explicitOperations.Length == 1)
                {
                    var topmostExplicitOperations = explicitOperations[0].GetTopmostExplicitDescendants();
                    if (topmostExplicitOperations.Length == 1 &&
                        topmostExplicitOperations[0].Kind == OperationKind.Throw)
                    {
                        // Body that just throws.
                        return true;
                    }
                }
            }

            return false;
        }

        private static void AnalyzeOperationBlock(OperationBlockAnalysisContext context, INamedTypeSymbol iDisposableTypeSymbol)
        {
            if (context.OwningSymbol.Kind != SymbolKind.Method)
            {
                return;
            }

            var method = (IMethodSymbol)context.OwningSymbol;

            // We are only interested in private explicit interface implementations within a public non-sealed type.
            if (method.ExplicitInterfaceImplementations.IsEmpty ||
                method.GetResultantVisibility() != SymbolVisibility.Private ||
                method.ContainingType.IsSealed ||
                !method.ContainingType.IsExternallyVisible())
            {
                return;
            }

            // Avoid false reports from simple explicit implementations where the deriving type is not expected to access the base implementation.
            if (ShouldExcludeOperationBlock(context.OperationBlocks))
            {
                return;
            }

            var hasPublicInterfaceImplementation = false;
            foreach (IMethodSymbol interfaceMethod in method.ExplicitInterfaceImplementations)
            {
                // If any one of the explicitly implemented interface methods has a visible alternate, then effectively, they all do.
                if (HasVisibleAlternate(method.ContainingType, interfaceMethod, iDisposableTypeSymbol))
                {
                    return;
                }

                hasPublicInterfaceImplementation = hasPublicInterfaceImplementation ||
                    interfaceMethod.ContainingType.IsExternallyVisible();
            }

            // Even if none of the interface methods have alternates, there's only an issue if at least one of the interfaces is public.
            if (hasPublicInterfaceImplementation)
            {
                ReportDiagnostic(context, method.ContainingType.Name, method.Name);
            }
        }

        private static bool HasVisibleAlternate(INamedTypeSymbol namedType, IMethodSymbol interfaceMethod, INamedTypeSymbol iDisposableTypeSymbol)
        {
            foreach (INamedTypeSymbol type in namedType.GetBaseTypesAndThis())
            {
                foreach (IMethodSymbol method in type.GetMembers(interfaceMethod.Name).OfType<IMethodSymbol>())
                {
                    if (method.IsExternallyVisible())
                    {
                        return true;
                    }
                }
            }

            // This rule does not report a violation for an explicit implementation of IDisposable.Dispose when an externally visible Close() or System.IDisposable.Dispose(Boolean) method is provided.
            return interfaceMethod.Equals("Dispose") &&
                interfaceMethod.ContainingType.Equals(iDisposableTypeSymbol) &&
                namedType.GetBaseTypesAndThis().Any(t =>
                    t.GetMembers("Close").OfType<IMethodSymbol>().Any(m =>
                        m.IsExternallyVisible()));
        }

        private static void ReportDiagnostic(OperationBlockAnalysisContext context, params object[] messageArgs)
        {
            Diagnostic diagnostic = context.OwningSymbol.CreateDiagnostic(Rule, messageArgs);
            context.ReportDiagnostic(diagnostic);
        }

        #region Verifiers

        private static DiagnosticResult CSharpResult(int line, int column, string className, string methodName)
#pragma warning disable RS0030 // Do not used banned APIs
            => VerifyCS.Diagnostic()
                .WithLocation(line, column)
#pragma warning restore RS0030 // Do not used banned APIs
                .WithArguments(className, methodName);

        private static DiagnosticResult BasicResult(int line, int column, string className, string methodName)
#pragma warning disable RS0030 // Do not used banned APIs
            => VerifyVB.Diagnostic()
                .WithLocation(line, column)
#pragma warning restore RS0030 // Do not used banned APIs
                .WithArguments(className, methodName);

        #endregion

        #region CSharp

        [Fact]
        public async Task CA1033SimpleDiagnosticCasesCSharpAsync()
        {
            await VerifyCS.VerifyAnalyzerAsync(@"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
        DoSomething();
        int i = this[0];
        i = i + 1;
        string name = Name;
        Console.WriteLine(name);
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    // private, this is no good
    int DoSomething() { Console.WriteLine(this); return 0; }
    internal string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
    int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}
",
            CSharpResult(17, 21, "ImplementsGeneral", "IGeneral.DoSomething"),
            CSharpResult(25, 9, "ImplementsGeneral", "IGeneral.get_Item"),
            CSharpResult(35, 9, "ImplementsGeneral", "IGeneral.get_Name"),
            CSharpResult(55, 21, "ImplementsGeneralThree", "IGeneral.DoSomething"),
            CSharpResult(63, 9, "ImplementsGeneralThree", "IGeneral.get_Item"),
            CSharpResult(73, 9, "ImplementsGeneralThree", "IGeneral.get_Name"));
        }

        [Fact]
        public async Task CA1033NestedDiagnosticCasesCSharpAsync()
        {
            await VerifyCS.VerifyAnalyzerAsync(@"
using System;

public class NestedExplicitInterfaceImplementation
{
    public interface INestedGeneral
    {
        object DoSomething();
        void DoNothing();
        void JustThrow();
        int this[int item] { get; }
        string Name { get; }
        event EventHandler TheEvent;
    }

    public class ImplementsNestedGeneral : INestedGeneral
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        object INestedGeneral.DoSomething() { return null; }

        void INestedGeneral.DoNothing() { }
        void INestedGeneral.JustThrow() { throw new Exception(); }

        int INestedGeneral.this[int item]
        {
            // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
            get
            {
                Console.WriteLine(this);
                return item;
            }
        }

        string INestedGeneral.Name
        {
            // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
            get
            {
                Console.WriteLine(this);
                return ""name"";
            }
        }

        event EventHandler INestedGeneral.TheEvent
        {
            // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
            add
            { Console.WriteLine(this); }
            // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
            remove
            { Console.WriteLine(this); }
        }
    }
}
",
            CSharpResult(19, 31, "ImplementsNestedGeneral", "NestedExplicitInterfaceImplementation.INestedGeneral.DoSomething"),
            CSharpResult(27, 13, "ImplementsNestedGeneral", "NestedExplicitInterfaceImplementation.INestedGeneral.get_Item"),
            CSharpResult(37, 13, "ImplementsNestedGeneral", "NestedExplicitInterfaceImplementation.INestedGeneral.get_Name"),
            CSharpResult(47, 13, "ImplementsNestedGeneral", "NestedExplicitInterfaceImplementation.INestedGeneral.add_TheEvent"),
            CSharpResult(50, 13, "ImplementsNestedGeneral", "NestedExplicitInterfaceImplementation.INestedGeneral.remove_TheEvent"));
        }

        [Fact]
        public async Task CA1033NoDiagnosticCasesCSharpAsync()
        {
            await VerifyCS.VerifyAnalyzerAsync(@"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public class ImplementsGeneral : IGeneral
{
    object IGeneral.DoSomething()
    {
        DoSomething(true);
        return null;
    }
    public object DoSomething(bool x) { return x; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        get
        {
            throw new Exception();
        }
    }

    string IGeneral.Name
    {
        get => throw new Exception();
    }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
        DoSomething(true);
        int i = this[0];
        i = i + 1;
        string name = Name;
        Console.WriteLine(name);
    }

    object IGeneral.DoSomething()
    {
        DoSomething(true);
        return null;
    }
    public object DoSomething(bool x) { return x; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    public string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
    public int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}

public class NestedExplicitInterfaceImplementation
{
    public interface INestedGeneral
    {
        object DoSomething();
        void DoNothing();
        void JustThrow();
        int this[int item] { get; }
        string Name { get; }
        event EventHandler TheEvent;
    }

    public class ImplementsNestedGeneral : INestedGeneral
    {
        object INestedGeneral.DoSomething()
        {
            DoSomething(true);
            return null;
        }
        public object DoSomething(bool x) { return x; }

        void INestedGeneral.DoNothing() { }
        void INestedGeneral.JustThrow() { throw new Exception(); }

        int INestedGeneral.this[int item]
        {
            get
            {
                throw new Exception();
            }
        }

        string INestedGeneral.Name
        {
            get => throw new Exception();
        }

        event EventHandler INestedGeneral.TheEvent
        {
            add
            { }
            remove
            { }
        }
    }
}
");
        }

        [Fact]
        public async Task CA1033ExpressionBodiedMemberCSharpAsync()
        {
            await VerifyCS.VerifyAnalyzerAsync(@"
using System;

public interface IGeneral
{
    object DoSomething();
}

public class ImplementsGeneral  : IGeneral
{
    object IGeneral.DoSomething() => null;
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
        DoSomething();
    }

    object IGeneral.DoSomething() => null;
    private int DoSomething() => 0;
}
",
            CSharpResult(11, 21, "ImplementsGeneral", "IGeneral.DoSomething"),
            CSharpResult(21, 21, "ImplementsGeneralThree", "IGeneral.DoSomething"));
        }

        protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesAnalyzer();
        }

        protected override CodeFixProvider GetBasicCodeFixProvider()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesFixer();
        }

        protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesAnalyzer();
        }

        protected override CodeFixProvider GetCSharpCodeFixProvider()
        {
            return new InterfaceMethodsShouldBeCallableByChildTypesFixer();
        }

        #region CSharp

        [Fact]
        public void CA1033SimpleDiagnosticCasesCSharp_MakeProtected()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    int DoSomething() { Console.WriteLine(this); return 0; }

    internal string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    protected int DoSomething() { Console.WriteLine(this); return 0; }

    protected string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";

            VerifyCSharpFix(code, expectedFixedCode);
        }

        [Fact, WorkItem(2616, "https://github.com/dotnet/roslyn/issues/2616")]
        public void CA1033SimpleDiagnosticCasesCSharp_ImplicitImpl()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    public object DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    public string Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";

            VerifyCSharpFix(code, expectedFixedCode);
        }


        public override FixAllProvider GetFixAllProvider()
        {
            return WellKnownFixAllProviders.BatchFixer;
        }

        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
            SyntaxNode nodeToFix = root.FindNode(context.Span);
            if (nodeToFix == null)
            {
                return;
            }

            if (semanticModel.GetDeclaredSymbol(nodeToFix, context.CancellationToken) is not IMethodSymbol methodSymbol)
            {
                return;
            }

            SyntaxGenerator generator = SyntaxGenerator.GetGenerator(context.Document);
            SyntaxNode declaration = generator.GetDeclaration(nodeToFix);
            if (declaration == null)
            {
                return;
            }

            IMethodSymbol? candidateToIncreaseVisibility = GetExistingNonVisibleAlternate(methodSymbol);
            if (candidateToIncreaseVisibility != null)
            {
                ISymbol symbolToChange;
                bool checkSetter = false;
                if (candidateToIncreaseVisibility.IsAccessorMethod())
                {
                    symbolToChange = candidateToIncreaseVisibility.AssociatedSymbol;
                    if (methodSymbol.AssociatedSymbol.Kind == SymbolKind.Property)
                    {
                        var originalProperty = (IPropertySymbol)methodSymbol.AssociatedSymbol;
                        checkSetter = originalProperty.SetMethod != null;
                    }
                }
                else
                {
                    symbolToChange = candidateToIncreaseVisibility;
                }

                if (symbolToChange != null)
                {
                    string title = string.Format(CultureInfo.CurrentCulture, MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix1, symbolToChange.Name);

                    context.RegisterCodeFix(new MyCodeAction(title,
                         async ct => await MakeProtectedAsync(context.Document, symbolToChange, checkSetter, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix1),
                    context.Diagnostics);
                }
            }
            else
            {
                ISymbol symbolToChange = methodSymbol.IsAccessorMethod() ? methodSymbol.AssociatedSymbol : methodSymbol;
                if (symbolToChange != null)
                {
                    string title = string.Format(CultureInfo.CurrentCulture, MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix2, symbolToChange.Name);

                    context.RegisterCodeFix(new MyCodeAction(title,
                         async ct => await ChangeToPublicInterfaceImplementationAsync(context.Document, symbolToChange, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix2),
                    context.Diagnostics);
                }
            }

            context.RegisterCodeFix(new MyCodeAction(string.Format(CultureInfo.CurrentCulture, MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3, methodSymbol.ContainingType.Name),
                     async ct => await MakeContainingTypeSealedAsync(context.Document, methodSymbol, ct).ConfigureAwait(false),
                         equivalenceKey: MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3),
                context.Diagnostics);
        }

        private static IMethodSymbol? GetExistingNonVisibleAlternate(IMethodSymbol methodSymbol)
        {
            foreach (IMethodSymbol interfaceMethod in methodSymbol.ExplicitInterfaceImplementations)
            {
                foreach (INamedTypeSymbol type in methodSymbol.ContainingType.GetBaseTypesAndThis())
                {
                    IMethodSymbol candidate = type.GetMembers(interfaceMethod.Name).OfType<IMethodSymbol>().FirstOrDefault(m => !m.Equals(methodSymbol));
                    if (candidate != null)
                    {
                        return candidate;
                    }
                }
            }

            return null;
        }

        private static async Task<Document> MakeProtectedAsync(Document document, ISymbol symbolToChange, bool checkSetter, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            ISymbol? getter = null;
            ISymbol? setter = null;
            if (symbolToChange.Kind == SymbolKind.Property)
            {
                var propertySymbol = (IPropertySymbol)symbolToChange;
                getter = propertySymbol.GetMethod;
                setter = propertySymbol.SetMethod;
            }

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                docEditor.SetAccessibility(declaration, Accessibility.Protected);
            }, cancellationToken).ConfigureAwait(false);

            if (getter != null && getter.DeclaredAccessibility == Accessibility.Private)
            {
                await editor.EditAllDeclarationsAsync(getter, (docEditor, declaration) =>
                {
                    docEditor.SetAccessibility(declaration, Accessibility.NotApplicable);
                }, cancellationToken).ConfigureAwait(false);
            }

            if (checkSetter && setter != null && setter.DeclaredAccessibility == Accessibility.Private)
            {
                await editor.EditAllDeclarationsAsync(setter, (docEditor, declaration) =>
                {
                    docEditor.SetAccessibility(declaration, Accessibility.NotApplicable);
                }, cancellationToken).ConfigureAwait(false);
            }

            return editor.GetChangedDocuments().First();
        }

        private static async Task<Document> ChangeToPublicInterfaceImplementationAsync(Document document, ISymbol symbolToChange, CancellationToken cancellationToken)
        {
            SymbolEditor editor = SymbolEditor.Create(document);

            IEnumerable<ISymbol>? explicitImplementations = GetExplicitImplementations(symbolToChange);
            if (explicitImplementations == null)
            {
                return document;
            }

            await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) =>
            {
                SyntaxNode newDeclaration = declaration;
                foreach (ISymbol implementedMember in explicitImplementations)
                {
                    SyntaxNode interfaceTypeNode = docEditor.Generator.TypeExpression(implementedMember.ContainingType);
                    newDeclaration = docEditor.Generator.AsPublicInterfaceImplementation(newDeclaration, interfaceTypeNode);
                }

                docEditor.ReplaceNode(declaration, newDeclaration);
            }, cancellationToken).ConfigureAwait(false);

            return editor.GetChangedDocuments().First();
        }

        private static IEnumerable<ISymbol>? GetExplicitImplementations(ISymbol? symbol)
        {
            if (symbol == null)
            {
                return null;
            }

            return symbol.Kind switch
            {
                SymbolKind.Method => ((IMethodSymbol)symbol).ExplicitInterfaceImplementations,

                SymbolKind.Event => ((IEventSymbol)symbol).ExplicitInterfaceImplementations,

                SymbolKind.Property => ((IPropertySymbol)symbol).ExplicitInterfaceImplementations,

                _ => null,
            };
        }

        #region CSharp

        [Fact]
        public async Task CA1033SimpleDiagnosticCasesCSharp_MakeProtectedAsync()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.[|DoSomething|]() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    int DoSomething() { Console.WriteLine(this); return 0; }

    internal string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    protected int DoSomething() { Console.WriteLine(this); return 0; }

    protected string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";

            await VerifyCS.VerifyCodeFixAsync(code, expectedFixedCode);
        }

        [Fact, WorkItem(2616, "https://github.com/dotnet/roslyn/issues/2616")]
        public async Task CA1033SimpleDiagnosticCasesCSharp_ImplicitImplAsync()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.[|DoSomething|]() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    public object DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    public string Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}";

            await VerifyCS.VerifyCodeFixAsync(code, expectedFixedCode);
        }

        [Fact, WorkItem(2616, "https://github.com/dotnet/roslyn/issues/2616")]
        public async Task CA1033SimpleDiagnosticCasesCSharp_IndexerAsync()
        {
            var code = @"
using System;

public interface IGeneral
{
    int this[int item] { get; }
}

public class ImplementsGeneral  : IGeneral
{
    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return item;
        }
    }
}

public class ImplementsGeneralThree : IGeneral
{
    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return item;
        }
    }

    int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    int this[int item] { get; }
}

public class ImplementsGeneral  : IGeneral
{
    public int this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}

public class ImplementsGeneralThree : IGeneral
{
    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    protected int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}";

            await new VerifyCS.Test
            {
                TestState = { Sources = { code } },
                FixedState = { Sources = { expectedFixedCode } },
                NumberOfFixAllIterations = 2,
            }.RunAsync();
        }

        [Fact]
        public async Task CA1033SimpleDiagnosticCasesCSharp_MakeSealedAsync()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.[|DoSomething|]() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}
";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public sealed class ImplementsGeneral  : IGeneral
{
    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
}
";
            await new VerifyCS.Test
            {
                TestState = { Sources = { code } },
                FixedState = { Sources = { expectedFixedCode } },
                CodeActionIndex = 1,
                CodeActionEquivalenceKey = MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3,
            }.RunAsync();
        }

        [Fact]
        public async Task CA1033SimpleDiagnosticCasesCSharp_MakeSealed_2Async()
        {
            var code = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
        DoSomething();
        int i = this[0];
        i = i + 1;
        string name = Name;
        Console.WriteLine(name);
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.[|DoSomething|]() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        [|get|]
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    int DoSomething() { Console.WriteLine(this); return 0; }
    internal string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
    int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}
";
            var expectedFixedCode = @"
using System;

public interface IGeneral
{
    object DoSomething();
    void DoNothing();
    void JustThrow();

    int this[int item] { get; }
    string Name { get; }
}

public sealed class ImplementsGeneralThree : IGeneral
{
    public ImplementsGeneralThree()
    {
        DoSomething();
        int i = this[0];
        i = i + 1;
        string name = Name;
        Console.WriteLine(name);
    }

    // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
    object IGeneral.DoSomething() { return null; }

    void IGeneral.DoNothing() { }
    void IGeneral.JustThrow() { throw new Exception(); }

    int IGeneral.this[int item]
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }

    string IGeneral.Name
    {
        // [ExpectedWarning(""InterfaceMethodsShouldBeCallableByChildTypes"", ""DesignRules"")]
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }

    int DoSomething() { Console.WriteLine(this); return 0; }
    internal string Name
    {
        get
        {
            Console.WriteLine(this);
            return ""name"";
        }
    }
    int this[int item]
    {
        get
        {
            Console.WriteLine(this);
            return item;
        }
    }
}
";
            await new VerifyCS.Test
            {
                TestState = { Sources = { code } },
                FixedState = { Sources = { expectedFixedCode } },
                CodeActionIndex = 1,
                CodeActionEquivalenceKey = MicrosoftCodeQualityAnalyzersResources.InterfaceMethodsShouldBeCallableByChildTypesFix3,
            }.RunAsync();
        }

        [Fact]
        public async Task CA1033SimpleDiagnosticCasesCSharp_EventsAsync()
        {
            var code = @"
using System;

public class NestedExplicitInterfaceImplementation
{
    public interface INestedGeneral
    {
        event EventHandler TheEvent;
    }

    public class ImplementsNestedGeneral : INestedGeneral
    {
        event EventHandler INestedGeneral.TheEvent
        {
            [|add|]
            { Console.WriteLine(this); }
            [|remove|]
            { Console.WriteLine(this); }
        }

        event EventHandler TheEvent
        {
            add
            { Console.WriteLine(this); }
            remove
            { Console.WriteLine(this); }
        }  
    }
}
";
            var expectedFixedCode = @"
using System;

public class NestedExplicitInterfaceImplementation
{
    public interface INestedGeneral
    {
        event EventHandler TheEvent;
    }

    public class ImplementsNestedGeneral : INestedGeneral
    {
        event EventHandler INestedGeneral.TheEvent
        {
            add
            { Console.WriteLine(this); }
            remove
            { Console.WriteLine(this); }
        }

        protected event EventHandler TheEvent
        {
            add
            { Console.WriteLine(this); }
            remove
            { Console.WriteLine(this); }
        }  
    }
}
";
            await VerifyCS.VerifyCodeFixAsync(code, expectedFixedCode);
        }

namespace Softlr;

using System.Diagnostics.CodeAnalysis;

[SuppressMessage(SONARQUBE, S2339)]
public static partial class Suppress
{
    public const string CA1000 = "CA1000:DoNotDeclareStaticMembersOnGenericTypesAnalyzer";
    public const string CA1001 = "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposableAnalyzer";
    public const string CA1002 = "CA1002:DoNotExposeGenericLists";
    public const string CA1003 = "CA1003:UseGenericEventHandlerInstancesAnalyzer";
    public const string CA1005 = "CA1005:AvoidExcessiveParametersOnGenericTypes";
    public const string CA1008 = "CA1008:EnumsShouldHaveZeroValueAnalyzer";
    public const string CA1010 = "CA1010:CollectionsShouldImplementGenericInterfaceAnalyzer";
    public const string CA1012 = "CA1012:AbstractTypesShouldNotHaveConstructorsAnalyzer";
    public const string CA1014 = "CA1014:MarkAssembliesWithAttributesDiagnosticAnalyzer";
    public const string CA1016 = "CA1016:MarkAssembliesWithAttributesDiagnosticAnalyzer";
    public const string CA1017 = "CA1017:MarkAssembliesWithComVisibleAnalyzer";
    public const string CA1018 = "CA1018:MarkAttributesWithAttributeUsageAnalyzer";
    public const string CA1019 = "CA1019:DefineAccessorsForAttributeArgumentsAnalyzer";
    public const string CA1021 = "CA1021:AvoidOutParameters";
    public const string CA1024 = "CA1024:UsePropertiesWhereAppropriateAnalyzer";
    public const string CA1027 = "CA1027:EnumWithFlagsAttributeAnalyzer";
    public const string CA1028 = "CA1028:EnumStorageShouldBeInt32Analyzer";
    public const string CA1030 = "CA1030:UseEventsWhereAppropriateAnalyzer";
    public const string CA1031 = "CA1031:DoNotCatchGeneralExceptionTypesAnalyzer";
    public const string CA1032 = "CA1032:ImplementStandardExceptionConstructorsAnalyzer";
    public const string CA1033 = "CA1033:InterfaceMethodsShouldBeCallableByChildTypesAnalyzer";
    public const string CA1034 = "CA1034:NestedTypesShouldNotBeVisibleAnalyzer";
    public const string CA1036 = "CA1036:OverrideMethodsOnComparableTypesAnalyzer";
    public const string CA1040 = "CA1040:AvoidEmptyInterfacesAnalyzer";
    public const string CA1041 = "CA1041:ProvideObsoleteAttributeMessageAnalyzer";
    public const string CA1043 = "CA1043:UseIntegralOrStringArgumentForIndexersAnalyzer";
    public const string CA1044 = "CA1044:PropertiesShouldNotBeWriteOnlyAnalyzer";
    public const string CA1045 = "CA1045:DoNotPassTypesByReference";
    public const string CA1046 = "CA1046:DoNotOverloadOperatorEqualsOnReferenceTypes";
    public const string CA1047 = "CA1047:DoNotDeclareProtectedMembersInSealedTypes";
    public const string CA1050 = "CA1050:DeclareTypesInNamespacesAnalyzer";
    public const string CA1051 = "CA1051:DoNotDeclareVisibleInstanceFieldsAnalyzer";
    public const string CA1052 = "CA1052:StaticHolderTypesAnalyzer";
    public const string CA1054 = "CA1054:UriParametersShouldNotBeStringsAnalyzer";
    public const string CA1055 = "CA1055:UriReturnValuesShouldNotBeStringsAnalyzer";
    public const string CA1056 = "CA1056:UriPropertiesShouldNotBeStringsAnalyzer";
    public const string CA1058 = "CA1058:TypesShouldNotExtendCertainBaseTypesAnalyzer";
    public const string CA1060 = "CA1060:MovePInvokesToNativeMethodsClassAnalyzer";
    public const string CA1061 = "CA1061:DoNotHideBaseClassMethodsAnalyzer";
    public const string CA1062 = "CA1062:ValidateArgumentsOfPublicMethods";
    public const string CA1063 = "CA1063:ImplementIDisposableCorrectlyAnalyzer";
    public const string CA1064 = "CA1064:ExceptionsShouldBePublicAnalyzer";
    public const string CA1065 = "CA1065:DoNotRaiseExceptionsInUnexpectedLocationsAnalyzer";
    public const string CA1066 = "CA1066:EquatableAnalyzer";
    public const string CA1067 = "CA1067:EquatableAnalyzer";
    public const string CA1068 = "CA1068:CancellationTokenParametersMustComeLastAnalyzer";
    public const string CA1069 = "CA1069:EnumShouldNotHaveDuplicatedValues";
    public const string CA1070 = "CA1070:DoNotDeclareEventFieldsAsVirtual";
    public const string CA1200 = "CA1200:AvoidUsingCrefTagsWithAPrefixAnalyzer";
    public const string CA1303 = "CA1303:DoNotPassLiteralsAsLocalizedParameters";
    public const string CA1304 = "CA1304:SpecifyCultureInfoAnalyzer";
    public const string CA1305 = "CA1305:SpecifyIFormatProviderAnalyzer";
    public const string CA1307 = "CA1307:SpecifyStringComparisonAnalyzer";
    public const string CA1308 = "CA1308:NormalizeStringsToUppercaseAnalyzer";
    public const string CA1309 = "CA1309:UseOrdinalStringComparisonAnalyzer";
    public const string CA1310 = "CA1310:SpecifyStringComparisonAnalyzer";
    public const string CA1401 = "CA1401:PInvokeDiagnosticAnalyzer";
    public const string CA1416 = "CA1416:PlatformCompatibilityAnalyzer";
    public const string CA1417 = "CA1417:DoNotUseOutAttributeStringPInvokeParametersAnalyzer";
    public const string CA1418 = "CA1418:UseValidPlatformString";
    public const string CA1419 = "CA1419:ProvidePublicParameterlessSafeHandleConstructor";
    public const string CA1501 = "CA1501:CodeMetricsAnalyzer";
    public const string CA1502 = "CA1502:CodeMetricsAnalyzer";
    public const string CA1505 = "CA1505:CodeMetricsAnalyzer";
    public const string CA1506 = "CA1506:CodeMetricsAnalyzer";
    public const string CA1507 = "CA1507:UseNameofInPlaceOfStringAnalyzer";
    public const string CA1508 = "CA1508:AvoidDeadConditionalCode";
    public const string CA1509 = "CA1509:CodeMetricsAnalyzer";
    public const string CA1700 = "CA1700:DoNotNameEnumValuesReserved";
    public const string CA1707 = "CA1707:IdentifiersShouldNotContainUnderscoresAnalyzer";
    public const string CA1708 = "CA1708:IdentifiersShouldDifferByMoreThanCaseAnalyzer";
    public const string CA1710 = "CA1710:IdentifiersShouldHaveCorrectSuffixAnalyzer";
    public const string CA1711 = "CA1711:IdentifiersShouldNotHaveIncorrectSuffixAnalyzer";
    public const string CA1712 = "CA1712:DoNotPrefixEnumValuesWithTypeNameAnalyzer";
    public const string CA1713 = "CA1713:EventsShouldNotHaveBeforeOrAfterPrefix";
    public const string CA1715 = "CA1715:IdentifiersShouldHaveCorrectPrefixAnalyzer";
    public const string CA1716 = "CA1716:IdentifiersShouldNotMatchKeywordsAnalyzer";
    public const string CA1720 = "CA1720:IdentifiersShouldNotContainTypeNames";
    public const string CA1721 = "CA1721:PropertyNamesShouldNotMatchGetMethodsAnalyzer";
    public const string CA1724 = "CA1724:TypeNamesShouldNotMatchNamespacesAnalyzer";
    public const string CA1725 = "CA1725:ParameterNamesShouldMatchBaseDeclarationAnalyzer";
    public const string CA1727 = "CA1727:LoggerMessageDefineAnalyzer";
    public const string CA1801 = "CA1801:ReviewUnusedParametersAnalyzer";
    public const string CA1802 = "CA1802:UseLiteralsWhereAppropriateAnalyzer";
    public const string CA1805 = "CA1805:DoNotInitializeUnnecessarilyAnalyzer";
    public const string CA1806 = "CA1806:DoNotIgnoreMethodResultsAnalyzer";
    public const string CA1810 = "CA1810:InitializeStaticFieldsInlineAnalyzer";
    public const string CA1812 = "CA1812:AvoidUninstantiatedInternalClassesAnalyzer";
    public const string CA1813 = "CA1813:AvoidUnsealedAttributesAnalyzer";
    public const string CA1814 = "CA1814:PreferJaggedArraysOverMultidimensionalAnalyzer";
    public const string CA1815 = "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypesAnalyzer";
    public const string CA1816 = "CA1816:CallGCSuppressFinalizeCorrectlyAnalyzer";
    public const string CA1819 = "CA1819:PropertiesShouldNotReturnArraysAnalyzer";
    public const string CA1820 = "CA1820:TestForEmptyStringsUsingStringLengthAnalyzer";
    public const string CA1821 = "CA1821:RemoveEmptyFinalizersAnalyzer";
    public const string CA1822 = "CA1822:MarkMembersAsStaticAnalyzer";
    public const string CA1823 = "CA1823:AvoidUnusedPrivateFieldsAnalyzer";
    public const string CA1824 = "CA1824:MarkAssembliesWithNeutralResourcesLanguageAnalyzer";
    public const string CA1825 = "CA1825:AvoidZeroLengthArrayAllocationsAnalyzer";

    public const string CA1826 =
        "CA1826:DoNotUseEnumerableMethodsOnIndexableCollectionsInsteadUseTheCollectionDirectlyAnalyzer";

    public const string CA1827 = "CA1827:UseCountProperlyAnalyzer";
    public const string CA1828 = "CA1828:UseCountProperlyAnalyzer";
    public const string CA1829 = "CA1829:UseCountProperlyAnalyzer";
    public const string CA1830 = "CA1830:PreferTypedStringBuilderAppendOverloads";
    public const string CA1831 = "CA1831:UseAsSpanInsteadOfRangeIndexerAnalyzer";
    public const string CA1832 = "CA1832:UseAsSpanInsteadOfRangeIndexerAnalyzer";
    public const string CA1833 = "CA1833:UseAsSpanInsteadOfRangeIndexerAnalyzer";
    public const string CA1834 = "CA1834:PreferConstCharOverConstUnitStringAnalyzer";
    public const string CA1835 = "CA1835:PreferStreamAsyncMemoryOverloads";
    public const string CA1836 = "CA1836:UseCountProperlyAnalyzer";
    public const string CA1837 = "CA1837:UseEnvironmentProcessId";
    public const string CA1838 = "CA1838:AvoidStringBuilderPInvokeParametersAnalyzer";
    public const string CA1839 = "CA1839:UseEnvironmentMembers";
    public const string CA1840 = "CA1840:UseEnvironmentMembers";
    public const string CA1841 = "CA1841:PreferDictionaryContainsMethods";
    public const string CA1842 = "CA1842:DoNotUseWhenAllOrWaitAllWithSingleArgument";
    public const string CA1843 = "CA1843:DoNotUseWhenAllOrWaitAllWithSingleArgument";
    public const string CA1844 = "CA1844:ProvideStreamMemoryBasedAsyncOverrides";
    public const string CA1845 = "CA1845:UseSpanBasedStringConcat";
    public const string CA1846 = "CA1846:PreferAsSpanOverSubstring";
    public const string CA1847 = "CA1847:UseStringContainsCharOverloadWithSingleCharactersAnalyzer";
    public const string CA1848 = "CA1848:LoggerMessageDefineAnalyzer";
    public const string CA2000 = "CA2000:DisposeObjectsBeforeLosingScope";
    public const string CA2002 = "CA2002:DoNotLockOnObjectsWithWeakIdentityAnalyzer";
    public const string CA2007 = "CA2007:DoNotDirectlyAwaitATaskAnalyzer";
    public const string CA2008 = "CA2008:DoNotCreateTasksWithoutPassingATaskSchedulerAnalyzer";
    public const string CA2009 = "CA2009:DoNotCallToImmutableCollectionOnAnImmutableCollectionValueAnalyzer";
    public const string CA2011 = "CA2011:AvoidInfiniteRecursion";
    public const string CA2012 = "CA2012:UseValueTasksCorrectlyAnalyzer";
    public const string CA2013 = "CA2013:DoNotUseReferenceEqualsWithValueTypesAnalyzer";
    public const string CA2014 = "CA2014:CSharpDoNotUseStackallocInLoopsAnalyzer";
    public const string CA2015 = "CA2015:DoNotDefineFinalizersForTypesDerivedFromMemoryManager";
    public const string CA2016 = "CA2016:ForwardCancellationTokenToInvocationsAnalyzer";
    public const string CA2017 = "CA2017:LoggerMessageDefineAnalyzer";
    public const string CA2018 = "CA2018:BufferBlockCopyLengthAnalyzer";
    public const string CA2100 = "CA2100:ReviewSqlQueriesForSecurityVulnerabilities";
    public const string CA2101 = "CA2101:PInvokeDiagnosticAnalyzer";
    public const string CA2109 = "CA2109:ReviewVisibleEventHandlersAnalyzer";
    public const string CA2119 = "CA2119:SealMethodsThatSatisfyPrivateInterfacesAnalyzer";
    public const string CA2153 = "CA2153:DoNotCatchCorruptedStateExceptionsAnalyzer";
    public const string CA2200 = "CA2200:RethrowToPreserveStackDetailsAnalyzer";
    public const string CA2201 = "CA2201:DoNotRaiseReservedExceptionTypesAnalyzer";
    public const string CA2207 = "CA2207:InitializeStaticFieldsInlineAnalyzer";
    public const string CA2208 = "CA2208:InstantiateArgumentExceptionsCorrectlyAnalyzer";
    public const string CA2211 = "CA2211:NonConstantFieldsShouldNotBeVisibleAnalyzer";
    public const string CA2213 = "CA2213:DisposableFieldsShouldBeDisposed";
    public const string CA2214 = "CA2214:DoNotCallOverridableMethodsInConstructorsAnalyzer";
    public const string CA2215 = "CA2215:DisposeMethodsShouldCallBaseClassDispose";
    public const string CA2216 = "CA2216:DisposableTypesShouldDeclareFinalizerAnalyzer";
    public const string CA2217 = "CA2217:EnumWithFlagsAttributeAnalyzer";
    public const string CA2219 = "CA2219:DoNotRaiseExceptionsInExceptionClausesAnalyzer";
    public const string CA2225 = "CA2225:OperatorOverloadsHaveNamedAlternatesAnalyzer";
    public const string CA2226 = "CA2226:OperatorsShouldHaveSymmetricalOverloadsAnalyzer";
    public const string CA2227 = "CA2227:CollectionPropertiesShouldBeReadOnlyAnalyzer";
    public const string CA2229 = "CA2229:SerializationRulesDiagnosticAnalyzer";
    public const string CA2231 = "CA2231:OverloadOperatorEqualsOnOverridingValueTypeEqualsAnalyzer";
    public const string CA2234 = "CA2234:PassSystemUriObjectsInsteadOfStringsAnalyzer";
    public const string CA2235 = "CA2235:SerializationRulesDiagnosticAnalyzer";
    public const string CA2237 = "CA2237:SerializationRulesDiagnosticAnalyzer";
    public const string CA2241 = "CA2241:ProvideCorrectArgumentsToFormattingMethodsAnalyzer";
    public const string CA2242 = "CA2242:TestForNaNCorrectlyAnalyzer";
    public const string CA2243 = "CA2243:AttributeStringLiteralsShouldParseCorrectlyAnalyzer";
    public const string CA2244 = "CA2244:AvoidDuplicateElementInitialization";
    public const string CA2245 = "CA2245:AvoidPropertySelfAssignment";
    public const string CA2246 = "CA2246:AssigningSymbolAndItsMemberInSameStatement";
    public const string CA2247 = "CA2247:DoNotCreateTaskCompletionSourceWithWrongArguments";
    public const string CA2248 = "CA2248:ProvideCorrectArgumentToEnumHasFlag";
    public const string CA2249 = "CA2249:PreferStringContainsOverIndexOfAnalyzer";
    public const string CA2250 = "CA2250:UseCancellationTokenThrowIfCancellationRequested";
    public const string CA2251 = "CA2251:UseStringEqualsOverStringCompare";
    public const string CA2252 = "CA2252:DetectPreviewFeatureAnalyzer";
    public const string CA2253 = "CA2253:LoggerMessageDefineAnalyzer";
    public const string CA2254 = "CA2254:LoggerMessageDefineAnalyzer";
    public const string CA2255 = "CA2255:ModuleInitializerAttributeShouldNotBeUsedInLibraries";
    public const string CA2256 = "CA2256:InterfaceMembersMissingImplementation";
    public const string CA2257 = "CA2257:MembersDeclaredOnImplementationTypeMustBeStatic";
    public const string CA2258 = "CA2258:DynamicInterfaceCastableImplementationUnsupported";
    public const string CA2300 = "CA2300:DoNotUseInsecureDeserializerBinaryFormatterMethods";
    public const string CA2301 = "CA2301:DoNotUseInsecureDeserializerBinaryFormatterWithoutBinder";
    public const string CA2302 = "CA2302:DoNotUseInsecureDeserializerBinaryFormatterWithoutBinder";
    public const string CA2305 = "CA2305:DoNotUseInsecureDeserializerLosFormatter";
    public const string CA2310 = "CA2310:DoNotUseInsecureDeserializerNetDataContractSerializerMethods";
    public const string CA2311 = "CA2311:DoNotUseInsecureDeserializerNetDataContractSerializerWithoutBinder";
    public const string CA2312 = "CA2312:DoNotUseInsecureDeserializerNetDataContractSerializerWithoutBinder";
    public const string CA2315 = "CA2315:DoNotUseInsecureDeserializerObjectStateFormatter";
    public const string CA2321 = "CA2321:DoNotUseInsecureDeserializerJavaScriptSerializerWithSimpleTypeResolver";
    public const string CA2322 = "CA2322:DoNotUseInsecureDeserializerJavaScriptSerializerWithSimpleTypeResolver";
    public const string CA2326 = "CA2326:JsonNetTypeNameHandling";
    public const string CA2327 = "CA2327:DoNotUseInsecureSettingsForJsonNet";
    public const string CA2328 = "CA2328:DoNotUseInsecureSettingsForJsonNet";
    public const string CA2329 = "CA2329:DoNotUseInsecureDeserializerJsonNetWithoutBinder";
    public const string CA2330 = "CA2330:DoNotUseInsecureDeserializerJsonNetWithoutBinder";
    public const string CA2350 = "CA2350:DoNotUseDataTableReadXml";
    public const string CA2351 = "CA2351:DoNotUseDataSetReadXml";
    public const string CA2352 = "CA2352:DataSetDataTableInSerializableTypeAnalyzer";
    public const string CA2353 = "CA2353:DataSetDataTableInSerializableTypeAnalyzer";
    public const string CA2354 = "CA2354:DataSetDataTableInIFormatterSerializableObjectGraphAnalyzer";
    public const string CA2355 = "CA2355:DataSetDataTableInSerializableObjectGraphAnalyzer";
    public const string CA2356 = "CA2356:DataSetDataTableInWebSerializableObjectGraphAnalyzer";
    public const string CA2361 = "CA2361:DoNotUseDataSetReadXml";
    public const string CA2362 = "CA2362:DataSetDataTableInSerializableTypeAnalyzer";
    public const string CA3001 = "CA3001:ReviewCodeForSqlInjectionVulnerabilities";
    public const string CA3002 = "CA3002:ReviewCodeForXssVulnerabilities";
    public const string CA3003 = "CA3003:ReviewCodeForFilePathInjectionVulnerabilities";
    public const string CA3004 = "CA3004:ReviewCodeForInformationDisclosureVulnerabilities";
    public const string CA3005 = "CA3005:ReviewCodeForLdapInjectionVulnerabilities";
    public const string CA3006 = "CA3006:ReviewCodeForCommandExecutionVulnerabilities";
    public const string CA3007 = "CA3007:ReviewCodeForOpenRedirectVulnerabilities";
    public const string CA3008 = "CA3008:ReviewCodeForXPathInjectionVulnerabilities";
    public const string CA3009 = "CA3009:ReviewCodeForXmlInjectionVulnerabilities";
    public const string CA3010 = "CA3010:ReviewCodeForXamlInjectionVulnerabilities";
    public const string CA3011 = "CA3011:ReviewCodeForDllInjectionVulnerabilities";
    public const string CA3012 = "CA3012:ReviewCodeForRegexInjectionVulnerabilities";
    public const string CA3061 = "CA3061:DoNotAddSchemaByURL";
    public const string CA3075 = "CA3075:DoNotUseInsecureDtdProcessingAnalyzer";
    public const string CA3076 = "CA3076:DoNotUseInsecureXSLTScriptExecutionAnalyzer";
    public const string CA3077 = "CA3077:DoNotUseInsecureDtdProcessingInApiDesignAnalyzer";
    public const string CA3147 = "CA3147:MarkVerbHandlersWithValidateAntiforgeryTokenAnalyzer";
    public const string CA5350 = "CA5350:DoNotUseInsecureCryptographicAlgorithmsAnalyzer";
    public const string CA5351 = "CA5351:DoNotUseInsecureCryptographicAlgorithmsAnalyzer";
    public const string CA5358 = "CA5358:ApprovedCipherModeAnalyzer";
    public const string CA5359 = "CA5359:DoNotDisableCertificateValidation";
    public const string CA5360 = "CA5360:DoNotCallDangerousMethodsInDeserialization";
    public const string CA5361 = "CA5361:DoNotSetSwitch";
    public const string CA5362 = "CA5362:PotentialReferenceCycleInDeserializedObjectGraph";
    public const string CA5363 = "CA5363:DoNotDisableRequestValidation";
    public const string CA5364 = "CA5364:DoNotUseDeprecatedSecurityProtocols";
    public const string CA5365 = "CA5365:DoNotDisableHTTPHeaderChecking";
    public const string CA5366 = "CA5366:UseXmlReaderForDataSetReadXml";
    public const string CA5367 = "CA5367:DoNotSerializeTypeWithPointerFields";
    public const string CA5368 = "CA5368:SetViewStateUserKey";
    public const string CA5369 = "CA5369:UseXmlReaderForDeserialize";
    public const string CA5370 = "CA5370:UseXmlReaderForValidatingReader";
    public const string CA5371 = "CA5371:UseXmlReaderForSchemaRead";
    public const string CA5372 = "CA5372:UseXmlReaderForXPathDocument";
    public const string CA5373 = "CA5373:DoNotUseObsoleteKDFAlgorithm";
    public const string CA5374 = "CA5374:DoNotUseXslTransform";
    public const string CA5375 = "CA5375:DoNotUseAccountSAS";
    public const string CA5376 = "CA5376:UseSharedAccessProtocolHttpsOnly";
    public const string CA5377 = "CA5377:UseContainerLevelAccessPolicy";
    public const string CA5378 = "CA5378:DoNotSetSwitch";
    public const string CA5379 = "CA5379:DoNotUseWeakKDFAlgorithm";
    public const string CA5380 = "CA5380:DoNotInstallRootCert";
    public const string CA5381 = "CA5381:DoNotInstallRootCert";
    public const string CA5382 = "CA5382:UseSecureCookiesASPNetCore";
    public const string CA5383 = "CA5383:UseSecureCookiesASPNetCore";
    public const string CA5384 = "CA5384:DoNotUseDSA";
    public const string CA5385 = "CA5385:UseRSAWithSufficientKeySize";
    public const string CA5386 = "CA5386:DoNotUseDeprecatedSecurityProtocols";
    public const string CA5387 = "CA5387:DoNotUseWeakKDFInsufficientIterationCount";
    public const string CA5388 = "CA5388:DoNotUseWeakKDFInsufficientIterationCount";
    public const string CA5389 = "CA5389:DoNotAddArchiveItemPathToTheTargetFileSystemPath";
    public const string CA5390 = "CA5390:DoNotHardCodeEncryptionKey";
    public const string CA5391 = "CA5391:UseAutoValidateAntiforgeryToken";
    public const string CA5392 = "CA5392:UseDefaultDllImportSearchPathsAttribute";
    public const string CA5393 = "CA5393:UseDefaultDllImportSearchPathsAttribute";
    public const string CA5394 = "CA5394:DoNotUseInsecureRandomness";
    public const string CA5395 = "CA5395:UseAutoValidateAntiforgeryToken";
    public const string CA5396 = "CA5396:SetHttpOnlyForHttpCookie";
    public const string CA5397 = "CA5397:SslProtocolsAnalyzer";
    public const string CA5398 = "CA5398:SslProtocolsAnalyzer";
    public const string CA5399 = "CA5399:DoNotDisableHttpClientCRLCheck";
    public const string CA5400 = "CA5400:DoNotDisableHttpClientCRLCheck";
    public const string CA5401 = "CA5401:DoNotUseCreateEncryptorWithNonDefaultIV";
    public const string CA5402 = "CA5402:DoNotUseCreateEncryptorWithNonDefaultIV";
    public const string CA5403 = "CA5403:DoNotHardCodeCertificate";
    public const string IL3000 = "IL3000:AvoidAssemblyLocationInSingleFile";
    public const string IL3001 = "IL3001:AvoidAssemblyLocationInSingleFile";
}

Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.InterfaceMethodsShouldBeCallableByChildTypesAnalyzer : DiagnosticAnalyzer

Fields :

public static DiagnosticDescriptor Rule

Constructors :

public InterfaceMethodsShouldBeCallableByChildTypesAnalyzer()

Methods :

public ImmutableArray<DiagnosticDescriptor> get_SupportedDiagnostics()
public Void Initialize(AnalysisContext analysisContext = )
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
public String ToString()
public Type GetType()