From 036ed6760cdb24534fbb31c395ca66d2c3be45bf Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Tue, 10 Sep 2024 15:33:31 -0500 Subject: [PATCH] Prevent duplicate validation of implemented interfaces (#109) --- .../Templates/Validations.sbntxt | 17 ++++--- .../IValidationTarget.cs | 19 ++++++++ .../ValidationResult.cs | 13 ++++++ .../DuplicateTypeVisitTests.cs | 34 ++++++++++++++ .../AnalyzerTests/AnalyzerTestHelpers.cs | 7 +-- .../ValidateClassAnalyzerTests.cs | 44 ++++++++++++++++++- ...ddIValidationTargetCodefixProviderTests.cs | 4 +- ...ddValidateAttributeCodefixProviderTests.cs | 2 + .../CodeFixTests/CodeFixTestHelper.cs | 5 ++- ...#IV.Namespace..BaseInterface.g.verified.cs | 15 +++++-- ...#IV.Namespace..ValidateClass.g.verified.cs | 17 ++++--- ...rget#IV.Namespace..BaseClass.g.verified.cs | 15 +++++-- ...#IV.Namespace..ValidateClass.g.verified.cs | 17 ++++--- ...mespace.OuterClass.BaseClass.g.verified.cs | 15 +++++-- ...amespace.OuterClass.SubClass.g.verified.cs | 17 ++++--- ...IV.Namespace..IBaseInterface.g.verified.cs | 15 +++++-- ...est#IV.Namespace..IInterface.g.verified.cs | 17 ++++--- ...#IV.Namespace..ValidateClass.g.verified.cs | 15 +++++-- ...ace.OuterClass.ValidateClass.g.verified.cs | 15 +++++-- ...OuterInterface.ValidateClass.g.verified.cs | 15 +++++-- ...dStruct.ValidateRecordStruct.g.verified.cs | 15 +++++-- ...e.OuterRecord.ValidateRecord.g.verified.cs | 15 +++++-- ...e.OuterStruct.ValidateStruct.g.verified.cs | 15 +++++-- ...spaceTest#IV...ValidateClass.g.verified.cs | 15 +++++-- ...rayString#IV...ValidateClass.g.verified.cs | 15 +++++-- ...gNotEmpty#IV...ValidateClass.g.verified.cs | 15 +++++-- ...ionTarget#IV...ValidateClass.g.verified.cs | 15 +++++-- ...Target#IV...ValidationTarget.g.verified.cs | 15 +++++-- ...rayString#IV...ValidateClass.g.verified.cs | 15 +++++-- ...ionTarget#IV...ValidateClass.g.verified.cs | 15 +++++-- ...Target#IV...ValidationTarget.g.verified.cs | 15 +++++-- ...istString#IV...ValidateClass.g.verified.cs | 15 +++++-- ...gNotEmpty#IV...ValidateClass.g.verified.cs | 15 +++++-- ...istString#IV...ValidateClass.g.verified.cs | 15 +++++-- ...lidations#IV...ValidateClass.g.verified.cs | 15 +++++-- ...ionsInherited#IV...BaseClass.g.verified.cs | 15 +++++-- ...tionsInherited#IV...SubClass.g.verified.cs | 17 ++++--- ...ComplexValidator#IV...Target.g.verified.cs | 15 +++++-- ...ateMethod#IV...ValidateClass.g.verified.cs | 15 +++++-- ...validType#IV...ValidateClass.g.verified.cs | 15 +++++-- ...roperType#IV...ValidateClass.g.verified.cs | 15 +++++-- ...arameters#IV...ValidateClass.g.verified.cs | 15 +++++-- ...nericType#IV...ValidateClass.g.verified.cs | 15 +++++-- ...mptyOnInt#IV...ValidateClass.g.verified.cs | 15 +++++-- ...yOnString#IV...ValidateClass.g.verified.cs | 15 +++++-- ...nericType#IV...ValidateClass.g.verified.cs | 15 +++++-- ...nericType#IV...ValidateClass.g.verified.cs | 15 +++++-- ...rrayField#IV...ValidateClass.g.verified.cs | 15 +++++-- ...aramsConstructor#IV...Target.g.verified.cs | 15 +++++-- .../GeneratorTests/GeneratorTestHelper.cs | 3 +- ...hangeName#IV...ValidateClass.g.verified.cs | 15 +++++-- ...angesName#IV...ValidateClass.g.verified.cs | 15 +++++-- ...alidation#IV...ValidateClass.g.verified.cs | 15 +++++-- ...alidation#IV...ValidateClass.g.verified.cs | 15 +++++-- ...alidation#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- ...orMessage#IV...ValidateClass.g.verified.cs | 15 +++++-- ...torNameof#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eofStatic#IV...ValidateClass.g.verified.cs | 15 +++++-- ...torSimple#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- ...orMessage#IV...ValidateClass.g.verified.cs | 15 +++++-- ...torNameof#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eofStatic#IV...ValidateClass.g.verified.cs | 15 +++++-- ...torSimple#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- ...eArgument#IV...ValidateClass.g.verified.cs | 15 +++++-- 69 files changed, 788 insertions(+), 255 deletions(-) create mode 100644 tests/Immediate.Validations.FunctionalTests/IntegrationTests/DuplicateTypeVisitTests.cs diff --git a/src/Immediate.Validations.Generators/Templates/Validations.sbntxt b/src/Immediate.Validations.Generators/Templates/Validations.sbntxt index eed744a..61afe9a 100644 --- a/src/Immediate.Validations.Generators/Templates/Validations.sbntxt +++ b/src/Immediate.Validations.Generators/Templates/Validations.sbntxt @@ -16,9 +16,15 @@ partial {{ c.type }} {{ c.name }} partial {{ class.type }} {{ class.name }} { static ValidationResult IValidationTarget<{{ class.name }}>.Validate({{ class.name; if is_reference_type; "?"; end }} target) => - Validate(target); + Validate(target, []); - public static {{ if class.type == "interface"; "new"; end }} ValidationResult Validate({{ class.name; if is_reference_type; "?"; end }} target) + static ValidationResult IValidationTarget<{{ class.name }}>.Validate({{ class.name; if is_reference_type; "?"; end }} target, ValidationResult errors) => + Validate(target, errors); + + public static {{ if class.type == "interface"; "new"; end }} ValidationResult Validate({{ class.name; if is_reference_type; "?"; end }} target) => + Validate(target, []); + + public static {{ if class.type == "interface"; "new"; end }} ValidationResult Validate({{ class.name; if is_reference_type; "?"; end }} target, ValidationResult errors) { {{~ if is_reference_type ~}} if (target is not { } t) @@ -31,11 +37,12 @@ partial {{ class.type }} {{ class.name }} {{~ else ~}} var t = target; {{~ end ~}} - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof({{ class.name }}))) + return errors; + {{~ for bc in base_validation_targets ~}} - errors.AddRange({{ bc }}.Validate(t)); + {{ bc }}.Validate(t, errors); {{~ end ~}} {{~ if !skip_self ~}} diff --git a/src/Immediate.Validations.Shared/IValidationTarget.cs b/src/Immediate.Validations.Shared/IValidationTarget.cs index 6034ac8..cec602f 100644 --- a/src/Immediate.Validations.Shared/IValidationTarget.cs +++ b/src/Immediate.Validations.Shared/IValidationTarget.cs @@ -25,4 +25,23 @@ public interface IValidationTarget Justification = "This is a static method to validate an instance of the self type." )] static abstract ValidationResult Validate(T? target); + + /// + /// A method which can be used to validate instances of the type . + /// + /// + /// An instance of type which should be validated. + /// + /// + /// The operating to add validation entries to. + /// + /// + /// The parameter , for easier consumption. + /// + [SuppressMessage( + "Design", + "CA1000:Do not declare static members on generic types", + Justification = "This is a static method to validate an instance of the self type." + )] + static abstract ValidationResult Validate(T? target, ValidationResult errors); } diff --git a/src/Immediate.Validations.Shared/ValidationResult.cs b/src/Immediate.Validations.Shared/ValidationResult.cs index 82064f4..a9657bf 100644 --- a/src/Immediate.Validations.Shared/ValidationResult.cs +++ b/src/Immediate.Validations.Shared/ValidationResult.cs @@ -1,6 +1,7 @@ using System.Collections; using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; using System.Reflection; using System.Text.RegularExpressions; @@ -16,6 +17,18 @@ public sealed partial class ValidationResult : IEnumerable private static partial Regex FormatRegex(); private List? _errors; + private HashSet? _types; + + /// + /// Internal function used to support tracking which types have been visited as part of validation. + /// + /// + /// Should not be used by consumers. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Design", "CA1062:Validate arguments of public methods")] + public bool VisitType(Type type) => + (_types ??= []).Add(type.ToString()); /// /// Indicates whether the validation was successful. diff --git a/tests/Immediate.Validations.FunctionalTests/IntegrationTests/DuplicateTypeVisitTests.cs b/tests/Immediate.Validations.FunctionalTests/IntegrationTests/DuplicateTypeVisitTests.cs new file mode 100644 index 0000000..010f3ee --- /dev/null +++ b/tests/Immediate.Validations.FunctionalTests/IntegrationTests/DuplicateTypeVisitTests.cs @@ -0,0 +1,34 @@ +using Immediate.Validations.Shared; +using Xunit; + +namespace Immediate.Validations.FunctionalTests.IntegrationTests; + +public partial class DuplicateTypeVisitTests +{ + [Validate] + public partial interface IBaseInterface : IValidationTarget + { + public static int VisitCount { get; set; } + + private static void AdditionalValidations(ValidationResult _, IBaseInterface __) + { + VisitCount++; + } + } + + [Validate] + public partial interface ISubInterface : IBaseInterface, IValidationTarget; + + [Validate] + public sealed partial record ValidateRecord : IBaseInterface, ISubInterface, IValidationTarget; + + [Fact] + public void TypeValidatorsAreVisitedAtMostOnce() + { + var record = new ValidateRecord(); + + _ = ValidateRecord.Validate(record); + + Assert.Equal(1, IBaseInterface.VisitCount); + } +} diff --git a/tests/Immediate.Validations.Tests/AnalyzerTests/AnalyzerTestHelpers.cs b/tests/Immediate.Validations.Tests/AnalyzerTests/AnalyzerTestHelpers.cs index c02fea3..e040956 100644 --- a/tests/Immediate.Validations.Tests/AnalyzerTests/AnalyzerTestHelpers.cs +++ b/tests/Immediate.Validations.Tests/AnalyzerTests/AnalyzerTestHelpers.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; @@ -10,7 +11,7 @@ namespace Immediate.Validations.Tests.AnalyzerTests; public static class AnalyzerTestHelpers { public static CSharpAnalyzerTest CreateAnalyzerTest( - string inputSource + [StringSyntax("c#-test")] string inputSource ) where TAnalyzer : DiagnosticAnalyzer, new() { @@ -105,7 +106,7 @@ params DiagnosticResult[] diagnostics } public static CSharpSuppressorTest CreateSuppressorTest( - string inputSource + [StringSyntax("c#-test")] string inputSource ) where TSuppressor : DiagnosticSuppressor, new() { @@ -128,7 +129,7 @@ string inputSource } public static CSharpSuppressorTest CreateSuppressorTest( - string inputSource + [StringSyntax("c#-test")] string inputSource ) where TSuppressor : DiagnosticSuppressor, new() where TAnalyzer : DiagnosticAnalyzer, new() diff --git a/tests/Immediate.Validations.Tests/AnalyzerTests/ValidateClassAnalyzerTests.cs b/tests/Immediate.Validations.Tests/AnalyzerTests/ValidateClassAnalyzerTests.cs index 4a75afa..c810e5f 100644 --- a/tests/Immediate.Validations.Tests/AnalyzerTests/ValidateClassAnalyzerTests.cs +++ b/tests/Immediate.Validations.Tests/AnalyzerTests/ValidateClassAnalyzerTests.cs @@ -45,6 +45,7 @@ public sealed partial record Target : IValidationTarget public required int Unrelated { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -59,6 +60,7 @@ await AnalyzerTestHelpers.CreateAnalyzerTest( public sealed partial record {|IV0012:Target|} : IValidationTarget { public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -74,6 +76,7 @@ await AnalyzerTestHelpers.CreateAnalyzerTest( public sealed partial record {|IV0013:Target|} { public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -92,6 +95,7 @@ public sealed partial record Target : IValidationTarget public required string Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -110,6 +114,7 @@ public sealed partial record Target : IValidationTarget public required int Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -130,6 +135,7 @@ public enum ExampleEnum { None = 0, Value = 1 } public required ExampleEnum Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -148,6 +154,7 @@ public sealed partial record Target : IValidationTarget public required int Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -166,6 +173,7 @@ public sealed partial record Target : IValidationTarget public required string Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -184,6 +192,7 @@ public sealed partial record Target : IValidationTarget public required int Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -202,6 +211,7 @@ public sealed partial record Target : IValidationTarget public required List Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -220,6 +230,7 @@ public sealed partial record Target : IValidationTarget public required List Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -240,6 +251,7 @@ public enum ExampleEnum { None = 0, Value = 1 } public required List Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -258,6 +270,7 @@ public sealed partial record Target : IValidationTarget public required List Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -276,6 +289,7 @@ public sealed partial record Target : IValidationTarget public required string[] Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -294,6 +308,7 @@ public sealed partial record Target : IValidationTarget public required int[] Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -312,6 +327,7 @@ public sealed partial record Target : IValidationTarget public required int Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -330,6 +346,7 @@ public sealed partial record Target : IValidationTarget public required int Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -349,6 +366,7 @@ public sealed partial record Target : IValidationTarget public required int KeyValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -366,8 +384,9 @@ public sealed partial record Target : IValidationTarget [Equal({|IV0016:nameof(KeyValue)|})] public required int Id { get; init; } public required string KeyValue { get; init; } - + public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -386,6 +405,7 @@ public sealed partial record Target : IValidationTarget public required string Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -404,6 +424,7 @@ public sealed partial record Target : IValidationTarget public required string Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -423,6 +444,7 @@ public sealed partial record Target : IValidationTarget public required int KeyValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -442,6 +464,7 @@ public sealed partial record Target : IValidationTarget public required string KeyValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -480,6 +503,7 @@ public sealed partial record Target : IValidationTarget public required string FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -524,6 +548,7 @@ public sealed partial record Target : IValidationTarget public required int FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -556,6 +581,7 @@ public sealed partial record Target : IValidationTarget public required string FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -588,6 +614,7 @@ public sealed partial record Target : IValidationTarget public required int FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -620,6 +647,7 @@ public sealed partial record Target : IValidationTarget public required string FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -652,6 +680,7 @@ public sealed partial record Target : IValidationTarget public required int FirstValue { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -684,6 +713,7 @@ public sealed partial record Target : IValidationTarget public string FirstValue() => "Hello World!"; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -716,6 +746,7 @@ public sealed partial record Target : IValidationTarget public int FirstValue() => 123; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -748,6 +779,7 @@ public sealed partial record Target : IValidationTarget public static string FirstValue() => "Hello World!"; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -780,6 +812,7 @@ public sealed partial record Target : IValidationTarget public static int FirstValue() => 123; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -800,6 +833,7 @@ public sealed partial record Target : IValidationTarget private static readonly string[] Values = ["123", "456", "789"]; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -820,6 +854,7 @@ public sealed partial record Target : IValidationTarget private static readonly string[] Values = ["123", "456", "789"]; public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -839,6 +874,7 @@ public sealed partial record Target : IValidationTarget public required string Id { get; init; } public static ValidationResult Validate(Target target) => []; + public static ValidationResult Validate(Target target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -857,6 +893,7 @@ public partial class BaseClass : IValidationTarget public required int ValueA { get; init; } public static ValidationResult Validate(BaseClass target) => []; + public static ValidationResult Validate(BaseClass target, ValidationResult errors) => []; } [Validate] @@ -866,6 +903,7 @@ public partial class SubClass : BaseClass, IValidationTarget public required int ValueB { get; init; } public static ValidationResult Validate(SubClass target) => []; + public static ValidationResult Validate(SubClass target, ValidationResult errors) => []; } """ ).RunAsync(); @@ -884,7 +922,9 @@ public partial interface IBaseInterface : IValidationTarget int ValueA { get; } static ValidationResult IValidationTarget.Validate(IBaseInterface target) => []; + static ValidationResult IValidationTarget.Validate(IBaseInterface target, ValidationResult errors) => []; public static ValidationResult Validate(IBaseInterface target) => []; + public static ValidationResult Validate(IBaseInterface target, ValidationResult errors) => []; } [Validate] @@ -894,7 +934,9 @@ public partial interface IInterface : IBaseInterface, IValidationTarget.Validate(IInterface target) => []; + static ValidationResult IValidationTarget.Validate(IInterface target, ValidationResult errors) => []; public static ValidationResult Validate(IInterface target) => []; + public static ValidationResult Validate(IInterface target, ValidationResult errors) => []; } """ ).RunAsync(); diff --git a/tests/Immediate.Validations.Tests/CodeFixTests/AddIValidationTargetCodefixProviderTests.cs b/tests/Immediate.Validations.Tests/CodeFixTests/AddIValidationTargetCodefixProviderTests.cs index adbdfff..21123e3 100644 --- a/tests/Immediate.Validations.Tests/CodeFixTests/AddIValidationTargetCodefixProviderTests.cs +++ b/tests/Immediate.Validations.Tests/CodeFixTests/AddIValidationTargetCodefixProviderTests.cs @@ -20,7 +20,7 @@ public sealed record {|IV0013:Data|} namespace Immediate.Validations.Shared; [Validate] - public sealed record Data : {|CS0535:IValidationTarget|} + public sealed record Data : {|CS0535:{|CS0535:IValidationTarget|}|} { } """ @@ -46,7 +46,7 @@ public void Dispose() { } namespace Immediate.Validations.Shared; [Validate] - public sealed record Data : IDisposable, {|CS0535:IValidationTarget|} + public sealed record Data : IDisposable, {|CS0535:{|CS0535:IValidationTarget|}|} { public void Dispose() { } } diff --git a/tests/Immediate.Validations.Tests/CodeFixTests/AddValidateAttributeCodefixProviderTests.cs b/tests/Immediate.Validations.Tests/CodeFixTests/AddValidateAttributeCodefixProviderTests.cs index d0c8745..95e133d 100644 --- a/tests/Immediate.Validations.Tests/CodeFixTests/AddValidateAttributeCodefixProviderTests.cs +++ b/tests/Immediate.Validations.Tests/CodeFixTests/AddValidateAttributeCodefixProviderTests.cs @@ -14,6 +14,7 @@ namespace Immediate.Validations.Shared; public sealed record {|IV0012:Data|} : IValidationTarget { public static ValidationResult Validate(Data target) => []; + public static ValidationResult Validate(Data target, ValidationResult errors) => []; } """, $$""" @@ -23,6 +24,7 @@ namespace Immediate.Validations.Shared; public sealed record Data : IValidationTarget { public static ValidationResult Validate(Data target) => []; + public static ValidationResult Validate(Data target, ValidationResult errors) => []; } """ ).RunAsync(); diff --git a/tests/Immediate.Validations.Tests/CodeFixTests/CodeFixTestHelper.cs b/tests/Immediate.Validations.Tests/CodeFixTests/CodeFixTestHelper.cs index b09e452..b5e23a4 100644 --- a/tests/Immediate.Validations.Tests/CodeFixTests/CodeFixTestHelper.cs +++ b/tests/Immediate.Validations.Tests/CodeFixTests/CodeFixTestHelper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,8 +20,8 @@ public static class CodeFixTestHelper """; public static CSharpCodeFixTest CreateCodeFixTest( - string inputSource, - string fixedSource, + [StringSyntax("c#-test")] string inputSource, + [StringSyntax("c#-test")] string fixedSource, int codeActionIndex = 0 ) where TAnalyzer : DiagnosticAnalyzer, new() diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..BaseInterface.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..BaseInterface.g.verified.cs index 9267580..65bea16 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..BaseInterface.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..BaseInterface.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial interface BaseInterface { static ValidationResult IValidationTarget.Validate(BaseInterface? target) => - Validate(target); + Validate(target, []); - public static new ValidationResult Validate(BaseInterface? target) + static ValidationResult IValidationTarget.Validate(BaseInterface? target, ValidationResult errors) => + Validate(target, errors); + + public static new ValidationResult Validate(BaseInterface? target) => + Validate(target, []); + + public static new ValidationResult Validate(BaseInterface? target, ValidationResult errors) { if (target is not { } t) { @@ -22,9 +28,10 @@ static ValidationResult IValidationTarget.Validate(BaseInterface? { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(BaseInterface))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..ValidateClass.g.verified.cs index ad1510d..0e5e87d 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.ImplementBaseValidationInterface#IV.Namespace..ValidateClass.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -22,10 +28,11 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); - errors.AddRange(global::Namespace.BaseInterface.Validate(t)); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + + global::Namespace.BaseInterface.Validate(t, errors); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..BaseClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..BaseClass.g.verified.cs index 3b12564..e39e5fc 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..BaseClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..BaseClass.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial class BaseClass { static ValidationResult IValidationTarget.Validate(BaseClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(BaseClass? target) + static ValidationResult IValidationTarget.Validate(BaseClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(BaseClass? target) => + Validate(target, []); + + public static ValidationResult Validate(BaseClass? target, ValidationResult errors) { if (target is not { } t) { @@ -22,9 +28,10 @@ public static ValidationResult Validate(BaseClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(BaseClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..ValidateClass.g.verified.cs index 405fe58..41681a6 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritBaseValidationTarget#IV.Namespace..ValidateClass.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -22,10 +28,11 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); - errors.AddRange(global::Namespace.BaseClass.Validate(t)); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + + global::Namespace.BaseClass.Validate(t, errors); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.BaseClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.BaseClass.g.verified.cs index f678c12..10ba6c2 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.BaseClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.BaseClass.g.verified.cs @@ -13,9 +13,15 @@ partial class OuterClass partial class BaseClass { static ValidationResult IValidationTarget.Validate(BaseClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(BaseClass? target) + static ValidationResult IValidationTarget.Validate(BaseClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(BaseClass? target) => + Validate(target, []); + + public static ValidationResult Validate(BaseClass? target, ValidationResult errors) { if (target is not { } t) { @@ -24,9 +30,10 @@ public static ValidationResult Validate(BaseClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(BaseClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.SubClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.SubClass.g.verified.cs index c3211a8..1564590 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.SubClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedClassesTest#IV.Namespace.OuterClass.SubClass.g.verified.cs @@ -13,9 +13,15 @@ partial class OuterClass partial class SubClass { static ValidationResult IValidationTarget.Validate(SubClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(SubClass? target) + static ValidationResult IValidationTarget.Validate(SubClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(SubClass? target) => + Validate(target, []); + + public static ValidationResult Validate(SubClass? target, ValidationResult errors) { if (target is not { } t) { @@ -24,10 +30,11 @@ public static ValidationResult Validate(SubClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); - errors.AddRange(global::Namespace.OuterClass.BaseClass.Validate(t)); + if (!errors.VisitType(typeof(SubClass))) + return errors; + + global::Namespace.OuterClass.BaseClass.Validate(t, errors); __ValidateValueB(errors, t, t.ValueB); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IBaseInterface.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IBaseInterface.g.verified.cs index 2677667..ef86661 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IBaseInterface.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IBaseInterface.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial interface IBaseInterface { static ValidationResult IValidationTarget.Validate(IBaseInterface? target) => - Validate(target); + Validate(target, []); - public static new ValidationResult Validate(IBaseInterface? target) + static ValidationResult IValidationTarget.Validate(IBaseInterface? target, ValidationResult errors) => + Validate(target, errors); + + public static new ValidationResult Validate(IBaseInterface? target) => + Validate(target, []); + + public static new ValidationResult Validate(IBaseInterface? target, ValidationResult errors) { if (target is not { } t) { @@ -22,9 +28,10 @@ static ValidationResult IValidationTarget.Validate(IBaseInterfac { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(IBaseInterface))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IInterface.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IInterface.g.verified.cs index 0ae1dbc..66c97a4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IInterface.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.InheritedInterfacesTest#IV.Namespace..IInterface.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial interface IInterface { static ValidationResult IValidationTarget.Validate(IInterface? target) => - Validate(target); + Validate(target, []); - public static new ValidationResult Validate(IInterface? target) + static ValidationResult IValidationTarget.Validate(IInterface? target, ValidationResult errors) => + Validate(target, errors); + + public static new ValidationResult Validate(IInterface? target) => + Validate(target, []); + + public static new ValidationResult Validate(IInterface? target, ValidationResult errors) { if (target is not { } t) { @@ -22,10 +28,11 @@ static ValidationResult IValidationTarget.Validate(IInterface? targe { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); - errors.AddRange(global::Namespace.IBaseInterface.Validate(t)); + if (!errors.VisitType(typeof(IInterface))) + return errors; + + global::Namespace.IBaseInterface.Validate(t, errors); __ValidateValueB(errors, t, t.ValueB); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NamespaceTest#IV.Namespace..ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NamespaceTest#IV.Namespace..ValidateClass.g.verified.cs index 6cc1541..3d05543 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NamespaceTest#IV.Namespace..ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NamespaceTest#IV.Namespace..ValidateClass.g.verified.cs @@ -11,9 +11,15 @@ namespace Namespace; partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -22,9 +28,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedClassesTest#IV.Namespace.OuterClass.ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedClassesTest#IV.Namespace.OuterClass.ValidateClass.g.verified.cs index 95ba9ec..2ce8a3b 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedClassesTest#IV.Namespace.OuterClass.ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedClassesTest#IV.Namespace.OuterClass.ValidateClass.g.verified.cs @@ -13,9 +13,15 @@ partial class OuterClass partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -24,9 +30,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedInterfacesTest#IV.Namespace.OuterInterface.ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedInterfacesTest#IV.Namespace.OuterInterface.ValidateClass.g.verified.cs index 188af93..7e15fc6 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedInterfacesTest#IV.Namespace.OuterInterface.ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedInterfacesTest#IV.Namespace.OuterInterface.ValidateClass.g.verified.cs @@ -13,9 +13,15 @@ partial interface OuterInterface partial interface ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static new ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static new ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static new ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -24,9 +30,10 @@ static ValidationResult IValidationTarget.Validate(ValidateClass? { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordStructsTest#IV.Namespace.OuterRecordStruct.ValidateRecordStruct.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordStructsTest#IV.Namespace.OuterRecordStruct.ValidateRecordStruct.g.verified.cs index 6ce6f55..cc0beb7 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordStructsTest#IV.Namespace.OuterRecordStruct.ValidateRecordStruct.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordStructsTest#IV.Namespace.OuterRecordStruct.ValidateRecordStruct.g.verified.cs @@ -13,14 +13,21 @@ partial record struct OuterRecordStruct partial record struct ValidateRecordStruct { static ValidationResult IValidationTarget.Validate(ValidateRecordStruct target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateRecordStruct target) + static ValidationResult IValidationTarget.Validate(ValidateRecordStruct target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateRecordStruct target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateRecordStruct target, ValidationResult errors) { var t = target; - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateRecordStruct))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordsTest#IV.Namespace.OuterRecord.ValidateRecord.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordsTest#IV.Namespace.OuterRecord.ValidateRecord.g.verified.cs index 57aa951..1652029 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordsTest#IV.Namespace.OuterRecord.ValidateRecord.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedRecordsTest#IV.Namespace.OuterRecord.ValidateRecord.g.verified.cs @@ -13,9 +13,15 @@ partial record OuterRecord partial record ValidateRecord { static ValidationResult IValidationTarget.Validate(ValidateRecord? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateRecord? target) + static ValidationResult IValidationTarget.Validate(ValidateRecord? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateRecord? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateRecord? target, ValidationResult errors) { if (target is not { } t) { @@ -24,9 +30,10 @@ public static ValidationResult Validate(ValidateRecord? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateRecord))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedStructsTest#IV.Namespace.OuterStruct.ValidateStruct.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedStructsTest#IV.Namespace.OuterStruct.ValidateStruct.g.verified.cs index c356e41..659cbd0 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedStructsTest#IV.Namespace.OuterStruct.ValidateStruct.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NestedStructsTest#IV.Namespace.OuterStruct.ValidateStruct.g.verified.cs @@ -13,14 +13,21 @@ partial struct OuterStruct partial struct ValidateStruct { static ValidationResult IValidationTarget.Validate(ValidateStruct target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateStruct target) + static ValidationResult IValidationTarget.Validate(ValidateStruct target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateStruct target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateStruct target, ValidationResult errors) { var t = target; - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateStruct))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NoNamespaceTest#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NoNamespaceTest#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NoNamespaceTest#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ClassLocationTests.NoNamespaceTest#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayString#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayString#IV...ValidateClass.g.verified.cs index 45d7f12..31a2e05 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayString#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayString#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayStringNotEmpty#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayStringNotEmpty#IV...ValidateClass.g.verified.cs index e345544..0fb6198 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayStringNotEmpty#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayStringNotEmpty#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidateClass.g.verified.cs index 1d03334..26d1ca3 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateValidationTargets(errors, t, t.ValidationTargets); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidationTarget.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidationTarget.g.verified.cs index b33e0f0..576f2f8 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidationTarget.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayArrayValidationTarget#IV...ValidationTarget.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidationTarget { static ValidationResult IValidationTarget.Validate(ValidationTarget? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidationTarget? target) + static ValidationResult IValidationTarget.Validate(ValidationTarget? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidationTarget? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidationTarget? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidationTarget? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidationTarget))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayString#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayString#IV...ValidateClass.g.verified.cs index 2039f89..60ab952 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayString#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayString#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidateClass.g.verified.cs index eca01e9..dca81fc 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateValidationTargets(errors, t, t.ValidationTargets); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidationTarget.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidationTarget.g.verified.cs index b33e0f0..576f2f8 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidationTarget.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ArrayValidationTarget#IV...ValidationTarget.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidationTarget { static ValidationResult IValidationTarget.Validate(ValidationTarget? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidationTarget? target) + static ValidationResult IValidationTarget.Validate(ValidationTarget? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidationTarget? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidationTarget? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidationTarget? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidationTarget))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListString#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListString#IV...ValidateClass.g.verified.cs index 08fe121..7eb88ad 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListString#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListString#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListStringNotEmpty#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListStringNotEmpty#IV...ValidateClass.g.verified.cs index 7e2ebbe..98cd969 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListStringNotEmpty#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListListStringNotEmpty#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListString#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListString#IV...ValidateClass.g.verified.cs index 065d593..66cac18 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListString#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CollectionTests.ListString#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidations#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidations#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidations#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidations#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...BaseClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...BaseClass.g.verified.cs index d77d343..183d74a 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...BaseClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...BaseClass.g.verified.cs @@ -9,9 +9,15 @@ partial class BaseClass { static ValidationResult IValidationTarget.Validate(BaseClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(BaseClass? target) + static ValidationResult IValidationTarget.Validate(BaseClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(BaseClass? target) => + Validate(target, []); + + public static ValidationResult Validate(BaseClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(BaseClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(BaseClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...SubClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...SubClass.g.verified.cs index 686c4c2..9abe44a 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...SubClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.AdditionalValidationsInherited#IV...SubClass.g.verified.cs @@ -9,9 +9,15 @@ partial class SubClass { static ValidationResult IValidationTarget.Validate(SubClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(SubClass? target) + static ValidationResult IValidationTarget.Validate(SubClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(SubClass? target) => + Validate(target, []); + + public static ValidationResult Validate(SubClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,10 +26,11 @@ public static ValidationResult Validate(SubClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); - errors.AddRange(global::BaseClass.Validate(t)); + if (!errors.VisitType(typeof(SubClass))) + return errors; + + global::BaseClass.Validate(t, errors); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ComplexValidator#IV...Target.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ComplexValidator#IV...Target.g.verified.cs index 9fbd320..93567ca 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ComplexValidator#IV...Target.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ComplexValidator#IV...Target.g.verified.cs @@ -9,9 +9,15 @@ partial record Target { static ValidationResult IValidationTarget.Validate(Target? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(Target? target) + static ValidationResult IValidationTarget.Validate(Target? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(Target? target) => + Validate(target, []); + + public static ValidationResult Validate(Target? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(Target? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(Target))) + return errors; + __ValidateId(errors, t, t.Id); __ValidateFirstValue(errors, t, t.FirstValue); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationMissingValidateMethod#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationMissingValidateMethod#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationMissingValidateMethod#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationMissingValidateMethod#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnInvalidType#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnInvalidType#IV...ValidateClass.g.verified.cs index d700429..1be6a24 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnInvalidType#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnInvalidType#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnProperType#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnProperType#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnProperType#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidationOnProperType#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidatorWithParameters#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidatorWithParameters#IV...ValidateClass.g.verified.cs index 7d4f3fa..00dd4aa 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidatorWithParameters#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.CustomValidatorWithParameters#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.EnumAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.EnumAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs index 566536d..b0088c2 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.EnumAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.EnumAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateEnumProperty(errors, t, t.EnumProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnInt#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnInt#IV...ValidateClass.g.verified.cs index 3f291ca..80a80b5 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnInt#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnInt#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnString#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnString#IV...ValidateClass.g.verified.cs index 2a690d3..7c856db 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnString#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotEmptyOnString#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs index 7d4189c..d98a39d 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnGenericType#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnInvalidGenericType#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnInvalidGenericType#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnInvalidGenericType#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.NotNullAsCustomValidationOnInvalidGenericType#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.OneOfWithArrayField#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.OneOfWithArrayField#IV...ValidateClass.g.verified.cs index 090a220..8138ae4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.OneOfWithArrayField#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.OneOfWithArrayField#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ParamsConstructor#IV...Target.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ParamsConstructor#IV...Target.g.verified.cs index 9654f2f..572d582 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ParamsConstructor#IV...Target.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/CustomValidationTests.ParamsConstructor#IV...Target.g.verified.cs @@ -9,9 +9,15 @@ partial record Target { static ValidationResult IValidationTarget.Validate(Target? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(Target? target) + static ValidationResult IValidationTarget.Validate(Target? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(Target? target) => + Validate(target, []); + + public static ValidationResult Validate(Target? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(Target? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(Target))) + return errors; + __ValidateId(errors, t, t.Id); __ValidateFirstValue(errors, t, t.FirstValue); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/GeneratorTestHelper.cs b/tests/Immediate.Validations.Tests/GeneratorTests/GeneratorTestHelper.cs index 13c79c4..5b8ef9d 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/GeneratorTestHelper.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/GeneratorTestHelper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Immediate.Validations.Generators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -6,7 +7,7 @@ namespace Immediate.Validations.Tests.GeneratorTests; public static class GeneratorTestHelper { - public static GeneratorDriverRunResult RunGenerator(string source) + public static GeneratorDriverRunResult RunGenerator([StringSyntax("c#-test")] string source) { var syntaxTree = CSharpSyntaxTree.ParseText(source); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.EmptyDescriptionDoesntChangeName#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.EmptyDescriptionDoesntChangeName#IV...ValidateClass.g.verified.cs index dd7fc93..3bc510f 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.EmptyDescriptionDoesntChangeName#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.EmptyDescriptionDoesntChangeName#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateTesting(errors, t, t.Testing); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.FilledDescriptionChangesName#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.FilledDescriptionChangesName#IV...ValidateClass.g.verified.cs index 7b43c96..ea0ca7f 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.FilledDescriptionChangesName#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/MiscellaneousTests.FilledDescriptionChangesName#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateTesting(errors, t, t.Testing); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.EnumValidation#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.EnumValidation#IV...ValidateClass.g.verified.cs index 3b60ca0..76d09b2 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.EnumValidation#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.EnumValidation#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateTestEnum(errors, t, t.TestEnum); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NotNullValidation#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NotNullValidation#IV...ValidateClass.g.verified.cs index d700429..1be6a24 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NotNullValidation#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NotNullValidation#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NullDoesNotUseNotNullValidation#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NullDoesNotUseNotNullValidation#IV...ValidateClass.g.verified.cs index 230fd37..0350da4 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NullDoesNotUseNotNullValidation#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/NativeValidationTests.NullDoesNotUseNotNullValidation#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.ConstantAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.ConstantAttributeArgument#IV...ValidateClass.g.verified.cs index b19a01f..70291db 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.ConstantAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.ConstantAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EnumAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EnumAttributeArgument#IV...ValidateClass.g.verified.cs index 27c6d13..7ee673a 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EnumAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EnumAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateDummyValue(errors, t, t.DummyValue); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorMessage#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorMessage#IV...ValidateClass.g.verified.cs index 2919514..1a097d9 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorMessage#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorMessage#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameof#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameof#IV...ValidateClass.g.verified.cs index accb88c..e1fd061 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameof#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameof#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameofStatic#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameofStatic#IV...ValidateClass.g.verified.cs index 157f7e2..189c9fe 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameofStatic#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorNameofStatic#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorSimple#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorSimple#IV...ValidateClass.g.verified.cs index 81a45c1..92936bd 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorSimple#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.EqualValidatorSimple#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateIntProperty(errors, t, t.IntProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.FieldAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.FieldAttributeArgument#IV...ValidateClass.g.verified.cs index dbaf94b..87a552f 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.FieldAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.FieldAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorMessage#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorMessage#IV...ValidateClass.g.verified.cs index 4517a65..1702893 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorMessage#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorMessage#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameof#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameof#IV...ValidateClass.g.verified.cs index 74cc7b5..e40fe57 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameof#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameof#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameofStatic#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameofStatic#IV...ValidateClass.g.verified.cs index ec84300..ba45ed5 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameofStatic#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorNameofStatic#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorSimple#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorSimple#IV...ValidateClass.g.verified.cs index ab5f22c..5700699 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorSimple#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MaxLengthValidatorSimple#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MethodAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MethodAttributeArgument#IV...ValidateClass.g.verified.cs index 3f6e811..6cf9bba 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MethodAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.MethodAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticFieldAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticFieldAttributeArgument#IV...ValidateClass.g.verified.cs index cfb7dcd..f13ec14 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticFieldAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticFieldAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty); diff --git a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticMethodAttributeArgument#IV...ValidateClass.g.verified.cs b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticMethodAttributeArgument#IV...ValidateClass.g.verified.cs index 544c819..97e91d0 100644 --- a/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticMethodAttributeArgument#IV...ValidateClass.g.verified.cs +++ b/tests/Immediate.Validations.Tests/GeneratorTests/ValidatorArgumentTests.StaticMethodAttributeArgument#IV...ValidateClass.g.verified.cs @@ -9,9 +9,15 @@ partial class ValidateClass { static ValidationResult IValidationTarget.Validate(ValidateClass? target) => - Validate(target); + Validate(target, []); - public static ValidationResult Validate(ValidateClass? target) + static ValidationResult IValidationTarget.Validate(ValidateClass? target, ValidationResult errors) => + Validate(target, errors); + + public static ValidationResult Validate(ValidateClass? target) => + Validate(target, []); + + public static ValidationResult Validate(ValidateClass? target, ValidationResult errors) { if (target is not { } t) { @@ -20,9 +26,10 @@ public static ValidationResult Validate(ValidateClass? target) { ".self", "`target` must not be `null`." }, }; } - - var errors = new ValidationResult(); + if (!errors.VisitType(typeof(ValidateClass))) + return errors; + __ValidateStringProperty(errors, t, t.StringProperty);