public int CompareTo(Type other) { // Make sure that Pointer parameters are sorted last to avoid bug [#1098]. // The rest of the comparisons are not important, but they are there to // guarantee a stable order between program executions. int result = this.CurrentType.CompareTo(other.CurrentType); if (result == 0) { result = Pointer.CompareTo(other.Pointer); } if (result == 0) { result = Reference.CompareTo(other.Reference); } if (result == 0) { result = Array.CompareTo(other.Array); } if (result == 0) { result = CLSCompliant.CompareTo(other.CLSCompliant); } if (result == 0) { result = ElementCount.CompareTo(other.ElementCount); } return(result); }
public int CompareTo(Type other) { // Make sure that Pointer parameters are sorted last to avoid bug [#1098]. // The rest of the comparisons help maintain a stable order (useful for source control). // Note that CompareTo is stricter than Equals and that there is code in // DelegateCollection.Add that depends on this fact. int result = this.CurrentType.CompareTo(other.CurrentType); if (result == 0) { result = Pointer.CompareTo(other.Pointer); // Must come after array/ref, see issue [#1098] } if (result == 0) { result = Reference.CompareTo(other.Reference); } if (result == 0) { result = Array.CompareTo(other.Array); } // Note: CLS-compliance and element counts // are used for comparison calculations, in order // to maintain a stable sorting order, even though // they are not used in equality calculations. if (result == 0) { result = CLSCompliant.CompareTo(other.CLSCompliant); } if (result == 0) { result = ElementCount.CompareTo(other.ElementCount); } return(result); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares two phrases based on the following: /// 1) Compare the translatable parts with the fewest number of owning phrases. The /// phrase whose least prolific part has the most owning phrases sorts first. /// 2) Fewest translatable parts /// 3) Translatable part with the maximum number of owning phrases. /// 4) Reference (alphabetically) /// 5) Alphabetically by original phrase /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: /// Value /// Meaning /// Less than zero /// This object is less than the <paramref name="other"/> parameter. /// Zero /// This object is equal to <paramref name="other"/>. /// Greater than zero /// This object is greater than <paramref name="other"/>. /// </returns> /// ------------------------------------------------------------------------------------ public int CompareTo(TranslatablePhrase other) { int compare; // 1) // ENHANCE: Idea for a possible future optimization: compare = (TranslatableParts.Any() ? (-1) : m_parts[0] ) + (other.TranslatableParts.Any() ? 1 : -2); if (!other.TranslatableParts.Any()) { return(TranslatableParts.Any() ? -1 : 0); } if (!TranslatableParts.Any()) { return(1); } compare = other.TranslatableParts.Min(p => p.OwningPhrases.Count()) * 100 / other.TranslatableParts.Count() - TranslatableParts.Min(p => p.OwningPhrases.Count()) * 100 / TranslatableParts.Count(); if (compare != 0) { return(compare); } // 2) //compare = TranslatableParts.Count() - other.TranslatableParts.Count(); //if (compare != 0) // return compare; // 3) compare = other.TranslatableParts.Max(p => p.OwningPhrases.Count()) - TranslatableParts.Max(p => p.OwningPhrases.Count()); if (compare != 0) { return(compare); } // 4) compare = (Reference == null) ? (other.Reference == null? 0 : -1) : Reference.CompareTo(other.Reference); if (compare != 0) { return(compare); } // 5) return(PhraseInUse.CompareTo(other.PhraseInUse)); }