Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Commented Issue: Problem with a Must overload. [7131]

$
0
0
I'm having trouble using the following overload:
```
Must<T, TProperty>(Func<TProperty, bool> predicate)
```

The presence of the generic T in the method definition prevents concise usage such as:
```
RuleFor(x => x.Title).Must(s => !string.IsNullOrWhiteSpace(s) || s.Length == 0);
```
Instead I must type:
```
RuleFor(x => x.Title).Must((string s) => !string.IsNullOrWhiteSpace(s) || s.Length == 0);
```
The class being validated (T) is not used anywhere in the predicate and can be removed from the method signature.
Comments: I'm not able to reproduce this problem. The type inference takes care of this so there is no need to explicitly specify the type. The following compiles just fine using FluentValidation 3.4.6: ``` public class Demo { public string Title { get; set; } } public class DemoValidator : AbstractValidator<Demo> { public DemoValidator() { RuleFor(x => x.Title).Must(s => !string.IsNullOrWhiteSpace(s) || s.Length == 0); } } ``` If you're running the latest version, please put together a small sample that reproduces the problem. Thanks.

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>