protected override string OverrideError(object value) { if (value == null) { return(null); } IComparable val = (IComparable)value; if (number.GetType() != value.GetType()) { number = (IComparable)Convert.ChangeType(number, value.GetType()); // made just once } bool ok = (ComparisonType == ComparisonType.EqualTo && val.CompareTo(number) == 0) || (ComparisonType == ComparisonType.DistinctTo && val.CompareTo(number) != 0) || (ComparisonType == ComparisonType.GreaterThan && val.CompareTo(number) > 0) || (ComparisonType == ComparisonType.GreaterThanOrEqualTo && val.CompareTo(number) >= 0) || (ComparisonType == ComparisonType.LessThan && val.CompareTo(number) < 0) || (ComparisonType == ComparisonType.LessThanOrEqualTo && val.CompareTo(number) <= 0); if (ok) { return(null); } return(ValidationMessage._0ShouldBe12.NiceToString().FormatWith("{0}", ComparisonType.NiceToString(), number.ToString())); }
protected override string OverrideError(object value) { IList list = (IList)value; int val = list == null? 0: list.Count; if ((ComparisonType == ComparisonType.EqualTo && val.CompareTo(number) == 0) || (ComparisonType == ComparisonType.DistinctTo && val.CompareTo(number) != 0) || (ComparisonType == ComparisonType.GreaterThan && val.CompareTo(number) > 0) || (ComparisonType == ComparisonType.GreaterThanOrEqualTo && val.CompareTo(number) >= 0) || (ComparisonType == ComparisonType.LessThan && val.CompareTo(number) < 0) || (ComparisonType == ComparisonType.LessThanOrEqualTo && val.CompareTo(number) <= 0)) { return(null); } return(ValidationMessage.TheNumberOfElementsOf0HasToBe12.NiceToString().FormatWith("{0}", ComparisonType.NiceToString().FirstLower(), number.ToString())); }