DisplayName should be consistent between `RuleFor.ForEach` and `RuleForEach`
See original GitHub issueSystem Details
- FluentValidation version: 8.4
Issue Description
public class Foo
{
public List<int> Numbers { get; set; }
}
[Fact]
public void Should_show_property_name()
{
var validator = new InlineValidator<Foo>();
validator.RuleFor(x => x.Numbers).ForEach(x => x.GreaterThan(10));
validator.ShouldHaveValidationErrorFor(x => x.Numbers, new List<int>() {2})
.WithErrorMessage("'Numbers[0]' must be greater than '10'.");
validator = new InlineValidator<Foo>();
validator.RuleForEach(x => x.Numbers).GreaterThan(10);
validator.ShouldHaveValidationErrorFor(x => x.Numbers, new List<int>() {2})
.WithErrorMessage("'Numbers[0]' must be greater than '10'.");
}
maybe because https://github.com/JeremySkinner/FluentValidation/blob/2eb493886b3f2f630f6c82ae7fc1baf6f34ec496/src/FluentValidation/DefaultValidatorExtensions.cs#L1091 using a InlineValidator<IEnumerable<TElement>>()
with x=>x
lambda, so the MemberInfo
will be resolved as null.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
FluentValidation/Changelog.txt at main
... 28 May 2021 Display name generation should be consistent between RuleForEach and RuleFor.ForEach (#1231) Allow AddFluentValidation to be called directly ...
Read more >Overriding the Message — FluentValidation documentation
You can override the default error message for a validator by calling the WithMessage method on a validator definition: RuleFor(customer => customer.
Read more >c# - Fluent Validation: RuleForEach and also require the ...
Right now my best guess is to write two rules (where Terms is IReadOnlyCollection<TermData> : RuleFor(x => x.Terms).NotEmpty(); RuleForEach(x => ...
Read more >FluentValidation/FluentValidation 10.2.1 on GitHub
Fix display name generation should be consistent between RuleForEach and RuleFor.ForEach (#1231); Allow AddFluentValidation to be called directly on ...
Read more >Combat display name spoofing : r/exchangeserver
Figure I need to rule saying if the sender is outside the organization and the recipient is inside the organization, but not sure...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the updated example. This is technically the correct behaviour as the display name is the always the name of the property being validated. In this case, you’re not validating a property, so it will correctly be an empty string and you’re expected to provide a name using
WithName
.However I agree that this isn’t particularly intuitive or useful so will look at the implications of changing this for a future version.
Implemented in 40dbb78 and will be part of 10.2.