6using System.Collections.Immutable;
11 [DiagnosticAnalyzer(LanguageNames.CSharp)]
15 private static readonly DiagnosticDescriptor shouldUseSerializableTypesRule =
16 new DiagnosticDescriptor(
17 Constants.AnalyzerIdentifiers.FindOperationsWithNonSerializableArguments, FindOperationsWithNonSerializableArgumentsConstants.Title,
18 FindOperationsWithNonSerializableArgumentsConstants.Message, Constants.Categories.Design,
19 DiagnosticSeverity.Warning,
true,
20 helpLinkUri: HelpUrlBuilder.Build(
24 ImmutableArray.Create(shouldUseSerializableTypesRule);
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;
36 var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodNode);
37 var typeSymbol = methodSymbol.ContainingType;
39 if (typeSymbol.IsStereotype() && methodSymbol.IsRootDataPortalOperation())
41 foreach(var argument
in methodSymbol.Parameters)
43 var argumentType = argument.Type;
44 if (!argumentType.IsMobileObject() && !argumentType.IsSpecialTypeSerializable() &&
45 !argumentType.IsSerializableByMobileFormatter(context.Compilation) &&
46 !argument.GetAttributes().Any(_ => _.AttributeClass.IsInjectable()) &&
47 argumentType is INamedTypeSymbol namedArgument && !namedArgument.IsSerializable)
49 context.ReportDiagnostic(Diagnostic.Create(
50 shouldUseSerializableTypesRule, argument.Locations[0]));
override ImmutableArray< DiagnosticDescriptor > SupportedDiagnostics
override void Initialize(AnalysisContext context)