-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResultExtensionsGeneratorValidator.cs
More file actions
32 lines (26 loc) · 1.16 KB
/
ResultExtensionsGeneratorValidator.cs
File metadata and controls
32 lines (26 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using CSharpFunctionalExtensions.HttpResults.Generators.Rules;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace CSharpFunctionalExtensions.HttpResults.Generators;
/// <summary>
/// Validates the rules for the <see cref="ResultExtensionsGenerator" />.
/// </summary>
internal static class ResultExtensionsGeneratorValidator
{
private static readonly List<IRule> Rules = [new DuplicateMapperRule(), new ParameterlessConstructorRule()];
/// <summary>
/// Validates the rules for the generator.
/// </summary>
/// <param name="mapperClasses">The list of mapper classes to validate.</param>
/// <param name="context">The source production context for reporting diagnostics.</param>
/// <returns>True if all rules are satisfied; otherwise, false.</returns>
public static bool CheckRules(List<ClassDeclarationSyntax> mapperClasses, SourceProductionContext context)
{
var diagnostics = new List<Diagnostic>();
foreach (var rule in Rules)
diagnostics.AddRange(rule.Check(mapperClasses));
foreach (var diagnostic in diagnostics)
context.ReportDiagnostic(diagnostic);
return !diagnostics.Any();
}
}