/// <summary> /// Compares this entity to another entity. If both objects implement /// the <see cref="IIdentifiable"/> interface, then comparison is based /// on each object's <see cref="IIdentity"/>. Otherwise, comparison /// is based on reference equality. /// </summary> /// <param name="other">The entity to compare to.</param> /// <returns>A number reflecting the similarity of objects. /// A value of zero indicates equality; all other values indicate inequality. /// </returns> public int CompareTo(T other) { if (other == this) { return(0); } if (other == null) { return(-1); } IIdentifiable obj1 = this as IIdentifiable; IIdentifiable obj2 = other as IIdentifiable; if (obj1 != null && obj2 != null) { return(obj1.GetIdentity().CompareTo(obj2.GetIdentity())); } return(1); }
/// <summary> /// Compares this entity to another entity. If both objects implement /// the <see cref="IIdentifiable"/> interface, then comparison is based /// on each object's <see cref="IIdentity"/>. Otherwise, comparison /// is based on reference equality (handled by <see cref="Object.Equals(object)"/>.) /// </summary> /// <param name="obj">The entity to compare to.</param> /// <returns>A number reflecting the similarity of objects. /// A value of zero indicates equality; all other values indicate inequality. /// </returns> public int CompareTo(object obj) { if (obj == null) { return(-1); } if (this == obj) { return(0); } IIdentifiable obj1 = this as IIdentifiable; IIdentifiable obj2 = obj as IIdentifiable; if (obj1 != null && obj2 != null) { return(obj1.GetIdentity().CompareTo(obj2.GetIdentity())); } return(1); }