public override PConstrianResult test(object newValue) { var r = new PConstrianResults(list.Count); for (int i = 0; i < list.Count; i++) { var c = list[i]; r.Add(c.test(newValue)); } return(r); }
public override PConstrianResults apply <T>(T value, ref T property) { var r = new PConstrianResults(list.Count); var bc = int.MinValue; var bi = 0; //best correctnes and it's index for (int i = 0; i < list.Count; i++) { var c = list[i]; var tr = c.test(value); r.Add(tr); if (tr.status == PCostrainStatus.PASSED) { bi = i; break; } if (tr.status == PCostrainStatus.CORRECTED && tr.correctnes > bc) { bc = tr.correctnes; bi = i; } } list[bi].correct(value, ref property); return(r); }
/// <summary>Apply the value to given property considering all spefied constrains.</summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <param name="property"></param> /// <returns></returns> public virtual PConstrianResults apply <T>(T value, ref T property) { var r = new PConstrianResults(list.Count); for (int i = 0; i < list.Count; i++) { var c = list[i]; var tr = c.test(value); if (tr.status == PCostrainStatus.PASSED || tr.status == PCostrainStatus.CORRECTED) { c.correct(value, ref property); } else { pending.Add(c); } } var pc = 1; do { pc = pending.Count; for (int i = 0; i < pending.Count; i++) { var c = pending[i]; var tr = c.test(value); if (tr.status == PCostrainStatus.REFUSED) { continue; } c.correct(value, ref property); pending.RemoveAt(i); i--; } } while (pc > 0 && pc != pending.Count); return(r); }