예제 #1
0
 public int CompareTo(IIdentifier other)
 {
     if (ReferenceEquals(null, other))
     {
         return(1);
     }
     if (other is Identifier <TId> id)
     {
         if (this.GetType() != other.GetType())
         {
             throw new ArgumentException($"Cannot compare to an instance of {other.GetType().Name}");
         }
         return(this._id.CompareTo(id._id));
     }
     throw new ArgumentException($"Cannot compare to an instance of {other.GetType().Name}");
 }
예제 #2
0
    /// <summary>
    /// 比较引用与标识是否相等。
    /// </summary>
    /// <param name="other">给定的 <see cref="IIdentifier{TId}"/>。</param>
    /// <returns>返回布尔值。</returns>
    protected virtual bool ReferenceAndIdEquals(IIdentifier <TId> other)
    {
        if (ReferenceEquals(this, other))
        {
            return(true);
        }

        if (GetType() != other.GetType())
        {
            return(false);
        }

        return(Id.Equals(other.Id));
    }
예제 #3
0
        public int CompareTo(IIdentifier other)
        {
            if (ReferenceEquals(null, other))
            {
                return(-1);
            }
            if (other is Identifier id)
            {
                return(this._id.CompareTo(id._id));
            }

            // how to compare ids of different types?
            // I suppose it's arbitrary?
            // if so, a quick compare would be good
            return(string.CompareOrdinal(this.GetType().Name, other.GetType().Name));
        }