예제 #1
0
        /// <summary>
        /// Tests whether this object represents the same user as another instance of the same class
        /// </summary>
        /// <param name="obj">Other instance of the same class</param>
        /// <returns><c>true</c> if this instance is equal to <paramref name="obj"/>, <c>false</c> otherwise</returns>
        public override bool Equals(object obj)
        {
            if (base.Equals(obj))
            {
                return(true);
            }
            RegisteredUser other = obj as RegisteredUser;

            if (other == null)
            {
                return(false);
            }
            return(Id == other.Id);
        }
예제 #2
0
        /// <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));
        }
예제 #3
0
        /// <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));
        }