CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DoesChildOperationHaveRunLocalAnalyzer.cs
Go to the documentation of this file.
2using Microsoft.CodeAnalysis;
3using Microsoft.CodeAnalysis.CSharp;
4using Microsoft.CodeAnalysis.CSharp.Syntax;
5using Microsoft.CodeAnalysis.Diagnostics;
6using System.Collections.Immutable;
7using System.Linq;
8
9namespace Csla.Analyzers
10{
11 [DiagnosticAnalyzer(LanguageNames.CSharp)]
13 : DiagnosticAnalyzer
14 {
15 private static readonly DiagnosticDescriptor childHasRunLocalRule =
16 new DiagnosticDescriptor(
17 Constants.AnalyzerIdentifiers.DoesChildOperationHaveRunLocal, DoesChildOperationHaveRunLocalAnalyzerConstants.Title,
18 DoesChildOperationHaveRunLocalAnalyzerConstants.Message, Constants.Categories.Usage,
19 DiagnosticSeverity.Warning, true,
20 helpLinkUri: HelpUrlBuilder.Build(
21 Constants.AnalyzerIdentifiers.DoesChildOperationHaveRunLocal, nameof(DoesChildOperationHaveRunLocalAnalyzer)));
22
23 public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(childHasRunLocalRule);
24
25 public override void Initialize(AnalysisContext context)
26 {
27 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
28 context.EnableConcurrentExecution();
29 context.RegisterSyntaxNodeAction(AnalyzeMethodDeclaration, SyntaxKind.MethodDeclaration);
30 }
31
32 private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
33 {
34 var methodNode = (MethodDeclarationSyntax)context.Node;
35
36 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
37 var typeSymbol = methodSymbol.ContainingType;
38
39 if (typeSymbol.IsStereotype() && methodSymbol.IsChildDataPortalOperation() &&
40 methodSymbol.GetAttributes().Any(_ => _.AttributeClass.IsRunLocalAttribute()))
41 {
42 context.ReportDiagnostic(Diagnostic.Create(
43 childHasRunLocalRule, methodSymbol.Locations[0]));
44 }
45 }
46 }
47}
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics