I would like to create fluentValidation cutomer validator, So that I can use this custom validator in coming projects.
My class is and xxxxxxxxx-want to get custom method after implementation of code (I tried but not giving +ve output-see my following code)
- namespace ratenamespace
- {
- public class ratecmd
- {
- [NoODataProcedureParameter]
- public int? ProductId { get; set; }
-
- [NoODataProcedureParameter]
- public int? PlaceId { get; set; }
-
- [NoODataProcedureParameter]
- public int? Rate { get; set; }
- }
-
- public class ratecmdValidator : AbstractValidator
- {
- public ratecmd()
- {
- RuleFor(x => x.Rate).xxxxxxxxx;
- }}}
I have created seperate class for custom validator like this:
- public class myValidator : PropertyValidator
- {
- public myValidator()
- : base("{PropertyName} must be greater than zero and not null.") { }
-
- protected override bool IsValid(PropertyValidatorContext context)
- {
- int? rate = context.PropertyValue as int?;
- if (rate != null && rate <= 0)
- {
- return false;
- }
- return true;
- }
- }