CardShop.Models.Validator.Comparator.IsValid C# (CSharp) Метод

IsValid() защищенный Метод

protected IsValid ( object value, System.ComponentModel.DataAnnotations.ValidationContext ctx ) : System.ComponentModel.DataAnnotations.ValidationResult
value object
ctx System.ComponentModel.DataAnnotations.ValidationContext
Результат System.ComponentModel.DataAnnotations.ValidationResult
        protected override ValidationResult IsValid(object value, ValidationContext ctx)
        {
            // get the otherProperty value.
            var otherPropertyValue = ctx.ObjectInstance.GetType().GetProperty(otherProperty).GetValue(ctx.ObjectInstance, null);
            ValidationResult result;
            // check for not null values, and then compare the properties. The (int) cast is required by
            // Microsoft enum logic.
            if (value!= null && otherPropertyValue != null && ((IComparable)value).CompareTo((IComparable)otherPropertyValue) == (int)this.op)
            {
                result = ValidationResult.Success;
            }else{
                // call ErrorMessage generator
                result = new ValidationResult(GetErrorMessage(ctx.DisplayName));
            }

             return result;
        }