/// <summary> /// Checks whether this instance describes the same user (the same IP address) as another instance of this class /// </summary> /// <param name="obj">Another instance of this class</param> /// <returns><c>true</c> if <paramref name="obj"/> is an instance of this class describing the same user, <c>false</c> otherwise</returns> public override bool Equals(object obj) { if (base.Equals(obj)) { return(true); } AnonymousUser other = obj as AnonymousUser; if (other == null) { return(false); } return(Ip == other.Ip); }
/// <summary> /// Compares this instance to another user /// </summary> /// <param name="other">Another user</param> /// <remarks>Anonymous users sort smaller than registered users, in both classes, they are sorted alphabetically</remarks> /// <seealso cref="IComparable{T}.CompareTo"/> public override int CompareTo(User other) { AnonymousUser otherAnon = other as AnonymousUser; if (otherAnon != null) { return(Ip.CompareTo(otherAnon.Ip)); } RegisteredUser otherRegistered = other as RegisteredUser; if (otherRegistered != null) { return(-1); } return(base.CompareTo(other)); }
/// <summary> /// Compares this instance to another user /// </summary> /// <param name="other">Another user</param> /// <remarks>Anonymous users sort smaller than registered users, in both classes, they are sorted alphabetically</remarks> /// <seealso cref="IComparable{T}.CompareTo"/> public override int CompareTo(User other) { RegisteredUser otherRegistered = other as RegisteredUser; if (otherRegistered != null) { int result = Id.CompareTo(otherRegistered.Id); if (result != 0) { return(result); } return(UserName.CompareTo(otherRegistered.UserName)); } AnonymousUser otherAnon = other as AnonymousUser; if (otherAnon != null) { return(+1); } return(base.CompareTo(other)); }