Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Person
- {
- [Required]
- [IsOldEnoughAttr(20, ErrorMessage = "You're not old enough")]
- public int RandomAge { get; set; }
- }
- [AttributeUsge(AttributeTarges.Property, AllowMultiple = false)]
- public class IsOldEnoughAtr : ValidationAttribute
- {
- pub int _ageLimit { get; set; }
- public IsOldEnoughAttr(int age)
- {
- _ageLimit = age;
- }
- protected override ValidationResult IsValid(object value, ValidationContext validationContext)
- {
- int val = (int)value;
- if (val >= _ageLimit)
- return ValidationResult.Success;
- else
- return new ValidationResult(ErrorMessageString);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement