6using System.Collections.Immutable;
10 [DiagnosticAnalyzer(LanguageNames.CSharp)]
14 private static readonly DiagnosticDescriptor inheritsFromBusinessRuleRule =
15 new DiagnosticDescriptor(
16 Constants.AnalyzerIdentifiers.AsynchronousBusinessRuleInheritance,
17 AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzerConstants.Title,
18 AsynchronousBusinessRuleInheritingFromBusinessRuleAnalyzerConstants.Message,
19 Constants.Categories.Usage, DiagnosticSeverity.Error,
true,
20 helpLinkUri: HelpUrlBuilder.Build(
24 ImmutableArray.Create(inheritsFromBusinessRuleRule);
28 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
29 context.EnableConcurrentExecution();
30 context.RegisterSyntaxNodeAction(AnalyzeMethodDeclaration, SyntaxKind.MethodDeclaration);
33 private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
35 var methodNode = (MethodDeclarationSyntax)context.Node;
37 if (!methodNode.ContainsDiagnostics)
39 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
40 var typeSymbol = methodSymbol.ContainingType;
42 if(typeSymbol.IsBusinessRule() && methodSymbol.Name ==
"Execute" && methodSymbol.IsAsync)
44 context.ReportDiagnostic(Diagnostic.Create(
45 inheritsFromBusinessRuleRule, methodSymbol.Locations[0]));
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics
override void Initialize(AnalysisContext context)