public static void Max <TOwnerVM, TTargetVM, TValue>( this PropertyValidatorBuilder <TOwnerVM, TTargetVM, TValue> builder, TValue max, string message = null, object details = null ) where TOwnerVM : IViewModel where TTargetVM : IViewModel where TValue : IComparable { message = message ?? Localized.ValidationMax; builder.Custom((args) => { if (max.CompareTo(args.Value) < 0) { string msg = message.FormatWith(max); // DO NOT reuse parameter! args.AddError(msg, details); } }); }
public static void Min <TOwnerVM, TTargetVM, TValue>( this PropertyValidatorBuilder <TOwnerVM, TTargetVM, Nullable <TValue> > builder, TValue min, string message = null, object details = null ) where TOwnerVM : IViewModel where TTargetVM : IViewModel where TValue : struct, IComparable { message = message ?? Localized.ValidationMin; builder.Custom((args) => { if (args.Value.HasValue && min.CompareTo(args.Value) == 1) { string msg = message.FormatWith(min); // DO NOT reuse parameter! args.AddError(msg, details); } }); }
public static void Min <TOwnerVM, TTargetVM, TValue>( this PropertyValidatorBuilder <TOwnerVM, TTargetVM, TValue> builder, Func <TOwnerVM, TValue> minValueSelector, string message = null, object details = null ) where TOwnerVM : IViewModel where TTargetVM : IViewModel where TValue : IComparable { message = message ?? Localized.ValidationMin; builder.Custom((args) => { var minValue = minValueSelector(args.Owner); if (minValue.CompareTo(args.Value) == 1) { string msg = message.FormatWith(minValue); // DO NOT reuse parameter! args.AddError(msg, details); } }); }