Quantcast
Channel: Fluent Validation for .NET
Browsing all 1917 articles
Browse latest View live
↧

New Post: How to create validator for type?

Use must:RuleFor(x=>x.Value).Must(val=> val is int); You could then easily wrap that in an extension method.

View Article


New Post: How to create validator for type?

I was trying a custom validator: public class TypeValidator<T> : PropertyValidator { public TypeValidator() : base("The type is not valid") { } protected override Boolean...

View Article


New Post: How to create validator for type?

To be honest, I wouldn't bother with a custom validator. Just wrap the Must call. Jeremy

View Article

New Post: How to create validator for type?

What do you mean "just wrap the must call"? Could you give me an example. One thing that I often use is to use String on my model properties and test if it is an Int32, a Double, a DateTime, etc ... I...

View Article

New Post: How to create validator for type?

I mean, you can put the logic for checking the type in a Must call which is wrapped in an extension method. This is just as reusable, but doesn't require a custom validator. public static class...

View Article


New Post: How to create validator for type?

I see what you meant ... And could this be used as ``` RuleFor(x => x.Forename).CanConvert<int>() ``` This is what I was looking for so I do not need to use typeof. Thank You

View Article

New Post: How to create validator for type?

Not really. If you try to use generics for this, then you'd need to also specify the type of the validator in the call to CanConvert. Here's how you'd do it:public static class MyExtensions { public...

View Article

New Post: Localized Message Issue

Hi Jeremy, I read the threads showing the implementation of Localized Messages generated through Resources. However, for my project I am fetching the resources from the database on start of the...

View Article


New Post: Localized Message Issue

Hi So the WithLocalizedMessage that you're using doesn't actually take a real lambda - it is literally only used to specify a resource type and resource name, using the standard resex files...

View Article


New Post: Localized Message Issue

Hi Jeremy, Thank you for a very quick reply. I have implemented the code that you suggested. However, I am not able to find "rule.Configure" method, when I try to implement:public static class...

View Article

New Post: Localized Message Issue

Sorry, my mistake - it should be IRuleBuilderOptions not IRuleBuilderpublic static class MyExtensions { public static IRuleBuilderOptions<T, TProperty> MyLocalizeMethod<T, TProperty>(this...

View Article

New Post: How to create validator for type?

I will go with your extension that uses Must ... The problem is sometimes I need to use String properties on my models to check if a user inserted, for example, a valid number. But then I loose the...

View Article

New Post: How to compare email and confirmemail?

Hi, I have next rule to make sure the user enters the same email again. Similar to a password confirmation. However, the rule keeps on being fired in the browser. So I cannot pass it. I have no clue...

View Article


New Post: How to compare email and confirmemail?

Looks fine to me. Is it perhaps the client-side validation that's executing incorrectly? Try running with server-side validation only and see if that makes a difference.

View Article

New Post: How to compare email and confirmemail?

hmm. I found a post here with Password and ConfirmPassword. I have no idea how to run server-side validation. I ready something on ExplicitServer. Do you have a thread to read more on it? The view with...

View Article


New Post: How to compare email and confirmemail?

Hi, Must be related to NOP. In customer registration it works, but for address (with javascript AJAX loading) not. I posted here in...

View Article

New Post: Unit Testing on Rule for a List

Hi!, I'm having an issue with writing a Unit Test for a Rule that's setted for checking the Length of a List of custom objects. The Rule is a follows: public class OrderValidator :...

View Article


New Post: Unit Testing on Rule for a List

Hi You won't be able to use the ShouldHaveValidationErrorFor method for this - it only works for settable properties. You'll need to invoke the validator manually and run assertions against the...

View Article

New Post: Unit Testing on Rule for a List

Cool, thanks!.

View Article

New Post: when condition not working as expected

I am very new to Fluent Validation and C# programming Below is my validator: public CustomerValidator() { When(customer => customer.IsPreferredCustomer, () => { RuleFor(customer =>...

View Article
Browsing all 1917 articles
Browse latest View live


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