Skip to content

Instantly share code, notes, and snippets.

@roughiain
Created May 18, 2023 07:26
Show Gist options
  • Save roughiain/38bb06ec8bd84390b8d9c358de743878 to your computer and use it in GitHub Desktop.
Save roughiain/38bb06ec8bd84390b8d9c358de743878 to your computer and use it in GitHub Desktop.
SampleModels for issue with dictionary and fluent variation
public class SomeThingSomething
{
     public string Name { get; set; } = "";
    
     public Dictionary<SomeEnum, SomeDetail> SomeDict { get; set; } = new();
  
}

public class SomeDetail
{
    public string Name { get; set; } = "";
    public string Surname { get; set; } = "";
}

public class SomeThingSomethingValidator : AbstractValidator<SomeThingSomething>
{
    public SomeThingSomethingValidator()
    {
        RuleFor(md => md.Name).NotNull().NotEmpty();
       
        // Can't get this to work...
        RuleForEach(m => m.SomeDict)
    }
}

public class SomeDetailValidator : AbstractValidator<SomeDetail>
{
    public SomeDetailValidator()
    {
        RuleFor(md => md.Name).NotNull().NotEmpty();
        RuleFor(md => md.Surname).NotNull().NotEmpty();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment