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; } } }
public static void ReportDiagnosticIfNonGenerated( this CompilationAnalysisContext context, Diagnostic diagnostic, Compilation compilation) { context.ReportDiagnosticIfNonGenerated(VisualBasic.GeneratedCodeRecognizer.Instance, diagnostic, compilation); }
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())); } } } }
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())); } } } }
public static void ReportDiagnosticIfNonGenerated(this CompilationAnalysisContext context, Diagnostic diagnostic) => context.ReportDiagnosticIfNonGenerated(CSharpGeneratedCodeRecognizer.Instance, diagnostic);