public Constrains GetCopy() { var result = new Constrains(Descedant, Ancestor) { IsComparable = this.IsComparable, Prefered = this.Prefered }; return(result); }
public IState MergeOrNull(Constrains constrains) { var result = new Constrains(Descedant, Ancestor) { IsComparable = this.IsComparable || constrains.IsComparable }; result.AddDescedant(constrains.Descedant); if (!result.TryAddAncestor(constrains.Ancestor)) { return(null); } if (result.HasAncestor && result.HasDescendant) { var anc = result.Ancestor; var des = result.Descedant; if (anc.Equals(des)) { if (result.IsComparable && !anc.IsComparable) { return(null); } return(anc); } if (!des.CanBeImplicitlyConvertedTo(anc)) { return(null); } } if (Prefered == null) { result.Prefered = constrains.Prefered; } else if (constrains.Prefered == null) { result.Prefered = Prefered; } else if (constrains.Prefered.Equals(Prefered)) { result.Prefered = Prefered; } else if (result.Fits(Prefered) && !result.Fits(constrains.Prefered)) { result.Prefered = Prefered; } else { result.Prefered = constrains.Prefered; } return(result); }