コード例 #1
0
        private static void CheckMembers(CompilationAnalysisContext c, INamedTypeSymbol analyzedClass)
        {
            foreach (var member in analyzedClass.GetMembers().Where(member => member.IsVirtual))
            {
                var syntax = member.DeclaringSyntaxReferences.First().GetSyntax();

                var methodDeclaration = syntax as MethodDeclarationSyntax;
                if (methodDeclaration != null)
                {
                    var keyword = methodDeclaration.Modifiers.First(m => m.IsKind(SyntaxKind.VirtualKeyword));
                    c.ReportDiagnosticIfNonGenerated(
                        Diagnostic.Create(Rule, keyword.GetLocation(), "virtual", "gratuitous"),
                        c.Compilation);
                    continue;
                }

                var propertyDeclaration = syntax as PropertyDeclarationSyntax;
                if (propertyDeclaration != null)
                {
                    var keyword = propertyDeclaration.Modifiers.First(m => m.IsKind(SyntaxKind.VirtualKeyword));
                    c.ReportDiagnosticIfNonGenerated(
                        Diagnostic.Create(Rule, keyword.GetLocation(), "virtual", "gratuitous"),
                        c.Compilation);
                    continue;
                }
            }
        }
コード例 #2
0
 public static void ReportDiagnosticIfNonGenerated(
     this CompilationAnalysisContext context,
     Diagnostic diagnostic,
     Compilation compilation)
 {
     context.ReportDiagnosticIfNonGenerated(VisualBasic.GeneratedCodeRecognizer.Instance, diagnostic, compilation);
 }
コード例 #3
0
        private static void ReportDisposeMethods(ImmutableHashSet <IMethodSymbol> allDisposeMethods, ImmutableHashSet <IMethodSymbol> implementingDisposeMethods,
                                                 ImmutableDictionary <INamedTypeSymbol, ImmutableHashSet <IMethodSymbol> > disposeMethodsCalledFromDispose, CompilationAnalysisContext c)
        {
            foreach (var dispose in allDisposeMethods.Except(implementingDisposeMethods))
            {
                if (MethodCalledFromDispose(disposeMethodsCalledFromDispose, dispose))
                {
                    continue;
                }

                foreach (var declaringSyntaxReference in dispose.DeclaringSyntaxReferences)
                {
                    var methodDeclaration =
                        declaringSyntaxReference.GetSyntax() as MethodDeclarationSyntax;
                    if (methodDeclaration != null)
                    {
                        c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation()));
                    }
                }
            }
        }
コード例 #4
0
        private static void ReportDisposeMethods(ImmutableHashSet<IMethodSymbol> allDisposeMethods, ImmutableHashSet<IMethodSymbol> implementingDisposeMethods,
            ImmutableDictionary<INamedTypeSymbol, ImmutableHashSet<IMethodSymbol>> disposeMethodsCalledFromDispose, CompilationAnalysisContext c)
        {
            foreach (var dispose in allDisposeMethods.Except(implementingDisposeMethods))
            {
                if (MethodCalledFromDispose(disposeMethodsCalledFromDispose, dispose))
                {
                    continue;
                }

                foreach (var declaringSyntaxReference in dispose.DeclaringSyntaxReferences)
                {
                    var methodDeclaration =
                        declaringSyntaxReference.GetSyntax() as MethodDeclarationSyntax;
                    if (methodDeclaration != null)
                    {
                        c.ReportDiagnosticIfNonGenerated(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation()));
                    }
                }
            }
        }
コード例 #5
0
        private static void CheckMembers(CompilationAnalysisContext c, INamedTypeSymbol analyzedClass)
        {
            foreach (var member in analyzedClass.GetMembers().Where(member => member.IsVirtual))
            {
                var syntax = member.DeclaringSyntaxReferences.First().GetSyntax();

                var methodDeclaration = syntax as MethodDeclarationSyntax;
                if (methodDeclaration != null)
                {
                    var keyword = methodDeclaration.Modifiers.First(m => m.IsKind(SyntaxKind.VirtualKeyword));
                    c.ReportDiagnosticIfNonGenerated(
                        Diagnostic.Create(Rule, keyword.GetLocation(), "virtual", "gratuitous"),
                        c.Compilation);
                    continue;
                }

                var propertyDeclaration = syntax as PropertyDeclarationSyntax;
                if (propertyDeclaration != null)
                {
                    var keyword = propertyDeclaration.Modifiers.First(m => m.IsKind(SyntaxKind.VirtualKeyword));
                    c.ReportDiagnosticIfNonGenerated(
                        Diagnostic.Create(Rule, keyword.GetLocation(), "virtual", "gratuitous"),
                        c.Compilation);
                    continue;
                }
            }
        }
コード例 #6
0
 public static void ReportDiagnosticIfNonGenerated(this CompilationAnalysisContext context, Diagnostic diagnostic) =>
 context.ReportDiagnosticIfNonGenerated(CSharpGeneratedCodeRecognizer.Instance, diagnostic);