Skip to content

Instantly share code, notes, and snippets.

@jorik041
Forked from karenpayneoregon/Child.cs
Created January 30, 2024 23:42
Show Gist options
  • Select an option

  • Save jorik041/f14889a418f2de44ca94d844f67aaf9f to your computer and use it in GitHub Desktop.

Select an option

Save jorik041/f14889a418f2de44ca94d844f67aaf9f to your computer and use it in GitHub Desktop.

Revisions

  1. @karenpayneoregon karenpayneoregon renamed this gist Jan 30, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @karenpayneoregon karenpayneoregon created this gist Jan 30, 2024.
    5 changes: 5 additions & 0 deletions Child.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    public class Child
    {
    public string Name;
    public int Age;
    }
    6 changes: 6 additions & 0 deletions Code.cs
    Original 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" }]
    };
    7 changes: 7 additions & 0 deletions Mast.cs
    Original 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;
    }
    32 changes: 32 additions & 0 deletions readme.md
    Original 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
    {
    ...
    }
    }
    }
    ```