-
-
Save jorik041/f14889a418f2de44ca94d844f67aaf9f to your computer and use it in GitHub Desktop.
Revisions
-
karenpayneoregon renamed this gist
Jan 30, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
karenpayneoregon created this gist
Jan 30, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ public class Child { public string Name; public int Age; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ Master master = new() { FamilyName = "Smith", ValidNames = ["Jim", "Mary", "Karen"], Children = [new Child { Name = "Mick" }] }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ public class Master { public int Id { get; set; } public string FamilyName { get; set; } public List<string> ValidNames; public List<Child> Children; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ Using [FluentValidation](https://www.nuget.org/packages/FluentValidation/11.9.0?_src=template) NuGet package, create a custom validator to validate that Master.Children contain one of the names in Master.ValidNames **Example** which goes not validate. ```csharp internal partial class Program { static void Main(string[] args) { Master master = new() { FamilyName = "Smith", ValidNames = ["Jim", "Mary", "Karen"], Children = [new Child { Name = "Mick" }] }; CustomValidator validator = new(); ValidationResult result = validator.Validate(master); Console.WriteLine(); if (result.IsValid) { ... } else { ... } } } ```