public static int ComparePreRelease(PreRelease left, PreRelease right) { //if (ReferenceEquals(left, null)) throw new ArgumentNullException("Left operand can't be null."); //if (ReferenceEquals(right, null)) throw new ArgumentNullException("Right operand can't be null."); if (ReferenceEquals(left, right)) { return(0); } else if (ReferenceEquals(left, null) && !ReferenceEquals(right, null) && right.Count == 0) { return(0); } else if (ReferenceEquals(left, null) && !ReferenceEquals(right, null) && right.Count > 0) { return(1); } else if (ReferenceEquals(right, null) && !ReferenceEquals(left, null) && left.Count == 0) { return(0); } else if (ReferenceEquals(right, null) && !ReferenceEquals(left, null) && left.Count > 0) { return(-1); } for (int i = 0; i < Math.Min(left.Count, right.Count); i++) { var ac = left[i]; var bc = right[i]; int anum, bnum; var isanum = Int32.TryParse(ac, out anum); var isbnum = Int32.TryParse(bc, out bnum); int r; if (isanum && isbnum) { r = anum.CompareTo(bnum); if (r != 0) { return(anum.CompareTo(bnum)); } } else { if (isanum) { return(-1); } if (isbnum) { return(1); } r = String.CompareOrdinal(ac, bc); if (r != 0) { return(r); } } } return(left.Count.CompareTo(right.Count)); }
public override bool Equals(object obj) { if (ReferenceEquals(obj, null)) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } PreRelease other = (PreRelease)obj; return(ComparePreRelease(this, other) == 0); }