Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. public class Person
  2. {
  3.  
  4.     [Required]
  5.         [IsOldEnoughAttr(20, ErrorMessage = "You're not old enough")]
  6.         public int RandomAge { get; set; }
  7.  
  8. }
  9.    
  10.     [AttributeUsge(AttributeTarges.Property, AllowMultiple = false)]
  11.     public class IsOldEnoughAtr : ValidationAttribute
  12.     {
  13.         pub int _ageLimit { get; set; }
  14.  
  15.         public IsOldEnoughAttr(int age)
  16.         {
  17.             _ageLimit = age;
  18.         }
  19.  
  20.         protected override ValidationResult IsValid(object value, ValidationContext validationContext)
  21.         {
  22.             int val = (int)value;
  23.  
  24.             if (val >= _ageLimit)
  25.                 return ValidationResult.Success;
  26.             else
  27.                 return new ValidationResult(ErrorMessageString);
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement