6using System.Collections.Immutable;
10 [DiagnosticAnalyzer(LanguageNames.CSharp)]
14 private static readonly DiagnosticDescriptor operationAttributeRule =
15 new DiagnosticDescriptor(
16 Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute, DoesOperationHaveAttributeAnalyzerConstants.Title,
17 DoesOperationHaveAttributeAnalyzerConstants.Message, Constants.Categories.Usage,
18 DiagnosticSeverity.Info,
true,
19 helpLinkUri: HelpUrlBuilder.Build(
22 public override ImmutableArray<DiagnosticDescriptor>
SupportedDiagnostics => ImmutableArray.Create(operationAttributeRule);
26 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
27 context.EnableConcurrentExecution();
28 context.RegisterSyntaxNodeAction(AnalyzeMethodDeclaration, SyntaxKind.MethodDeclaration);
31 private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
33 var methodNode = (MethodDeclarationSyntax)context.Node;
35 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
36 var typeSymbol = methodSymbol.ContainingType;
38 if (typeSymbol.IsStereotype())
40 var qualification = methodSymbol.IsDataPortalOperation();
42 if(qualification.ByNamingConvention && !qualification.ByAttribute)
44 context.ReportDiagnostic(Diagnostic.Create(
45 operationAttributeRule, methodSymbol.Locations[0]));
override void Initialize(AnalysisContext context)
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics