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.
IsBusinessObjectSerializableAnalyzer.cs
Go to the documentation of this file.
1using Microsoft.CodeAnalysis;
2using Microsoft.CodeAnalysis.CSharp;
3using Microsoft.CodeAnalysis.CSharp.Syntax;
4using Microsoft.CodeAnalysis.Diagnostics;
5using System.Collections.Immutable;
7
8namespace Csla.Analyzers
9{
10 [DiagnosticAnalyzer(LanguageNames.CSharp)]
12 : DiagnosticAnalyzer
13 {
14 private static readonly DiagnosticDescriptor makeSerializableRule =
15 new DiagnosticDescriptor(
16 Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable, IsBusinessObjectSerializableConstants.Title,
17 IsBusinessObjectSerializableConstants.Message, Constants.Categories.Usage,
18 DiagnosticSeverity.Error, true,
19 helpLinkUri: HelpUrlBuilder.Build(
20 Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable, nameof(IsBusinessObjectSerializableAnalyzer)));
21
22 public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(makeSerializableRule);
23
24 public override void Initialize(AnalysisContext context)
25 {
26 context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
27 context.EnableConcurrentExecution();
28 context.RegisterSyntaxNodeAction(AnalyzeClassDeclaration, SyntaxKind.ClassDeclaration);
29 }
30
31 private static void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context)
32 {
33 var classNode = (ClassDeclarationSyntax)context.Node;
34 var classSymbol = context.SemanticModel.GetDeclaredSymbol(classNode);
35
36 if (classSymbol.IsMobileObject() && !classSymbol.IsSerializable)
37 {
38 context.ReportDiagnostic(Diagnostic.Create(makeSerializableRule,
39 classNode.Identifier.GetLocation()));
40 }
41 }
42 }
43}
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics