/// <summary> /// Compares this <see cref="Entity"/> to another <see cref="Entity"/>. First "classname" attributes are compared, then "targetname". /// Attributes are compared alphabetically. Targetnames are only compared if classnames match. /// </summary> /// <param name="other"><see cref="Entity"/> to compare to.</param> /// <returns>Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.</returns> public int CompareTo(Entity other) { if (other == null) { return(1); } int comparison = ClassName.CompareTo(other.ClassName); return(comparison != 0 ? comparison : Name.CompareTo(other.Name)); }
/// <summary> /// Compares this <see cref="Entity"/> to another object. First "classname" attributes are compared, then "targetname". /// Attributes are compared alphabetically. Targetnames are only compared if classnames match. /// </summary> /// <param name="obj"><c>Object</c> to compare to.</param> /// <returns>Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.</returns> /// <exception cref="ArgumentException"><paramref name="obj"/> was not of type <see cref="Entity"/>.</exception> public int CompareTo(object obj) { if (obj == null) { return(1); } Entity other = obj as Entity; if (other == null) { throw new ArgumentException("Object is not an Entity"); } int comparison = ClassName.CompareTo(other.ClassName); return(comparison != 0 ? comparison : Name.CompareTo(other.Name)); }