© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
1 reply
petrus1337

❔ fluentvalidation custom validation inherit existing validation `MinimumLengthValidator`

Hello i trying to create custom validation by inherit fluentvalidator build in validator
MinimumLengthValidator
MinimumLengthValidator
(https://github.com/FluentValidation/FluentValidation/blob/main/src/FluentValidation/Validators/LengthValidator.cs#L111) but cant find any fitting to
SetValidator
SetValidator

the validator just overwrite default error message and doesnt do anything complicated
 public class Test<T> : MinimumLengthValidator<T> 
    {
        public override string Name => "Test";
        private readonly string _propertyPath;
        public Test(int min, string propertyPath) : base(max)
        {
            _propertyPath = propertyPath;
        }

        public Test(Func<T, int> max, string propertyPath) : base(min)
        {
            _propertyPath = propertyPath;
        }
        protected override string GetDefaultMessageTemplate(string errorCode) => "random";
 public class Test<T> : MinimumLengthValidator<T> 
    {
        public override string Name => "Test";
        private readonly string _propertyPath;
        public Test(int min, string propertyPath) : base(max)
        {
            _propertyPath = propertyPath;
        }

        public Test(Func<T, int> max, string propertyPath) : base(min)
        {
            _propertyPath = propertyPath;
        }
        protected override string GetDefaultMessageTemplate(string errorCode) => "random";

when i try register validator i get error
ruleBuilder.SetValidator(new Test<T>(min, propertyPath))
ruleBuilder.SetValidator(new Test<T>(min, propertyPath))
it complains that it cannot resolve method for it and candidates are (see pic) how am i supposed to do this?
image.png
GitHub
FluentValidation/LengthValidator.cs at main · FluentValidation/Flue...
A popular .NET validation library for building strongly-typed validation rules. - FluentValidation/LengthValidator.cs at main · FluentValidation/FluentValidation
FluentValidation/LengthValidator.cs at main · FluentValidation/Flue...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ FluentValidation Custom Client Response?
C#CC# / help
3y ago
❔ FluentValidation DTO
C#CC# / help
3y ago
❔ FluentValidation help
C#CC# / help
4y ago
ProblemDetails and FluentValidation
C#CC# / help
3y ago