Exemplo n.º 1
0
        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            Object instance     = context.ObjectInstance;
            Type   type         = instance.GetType();
            Object proprtyvalue = type.GetProperty(PropertyName).GetValue(instance, null);

            if (proprtyvalue.ToString() == DesiredValue.ToString() && (value == null || value.ToString().Length < MinLength))
            {
                if (ErrorMessageResourceType != null && !string.IsNullOrEmpty(ErrorMessageResourceName))
                {
                    var field = ErrorMessageResourceType.GetProperty(ErrorMessageResourceName);
                    if (field != null)
                    {
                        var val = field.GetValue(ErrorMessageResourceType, null) as string;
                        return(new ValidationResult(val));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(ErrorMessage))
                    {
                        return(new ValidationResult(ErrorMessage));
                    }
                }
            }
            return(ValidationResult.Success);
        }
        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            Object instance     = context.ObjectInstance;
            Type   type         = instance.GetType();
            Object proprtyvalue = type.GetProperty(PropertyName).GetValue(instance, null);

            if (Function(proprtyvalue.ToString(), DesiredValue.ToString()))
            {
                ValidationResult result = base.IsValid(value, context);
                return(result);
            }
            return(ValidationResult.Success);
        }