Beispiel #1
0
        public int CompareTo(Category other)
        {
            if (other == null)
            {
                return(0);
            }
            var messageCompare = String.Compare(Message, other.Message, StringComparison.Ordinal);

            if (messageCompare == 0)
            {
                var typeCompare = Type.CompareTo(other.Type);
                if (typeCompare == 0)
                {
                    return(Topic.CompareTo(other.Topic));
                }
                else
                {
                    return(typeCompare);
                }
            }
            else
            {
                return(messageCompare);
            }
        }
Beispiel #2
0
        public int CompareTo(object obj)
        {
            if (!(obj is Category))
            {
                return(1);                      // ??
            }
            var categoryObj    = (Category)obj;
            var nameComparison =
                (string.Compare(ProductName, categoryObj.ProductName, StringComparison.InvariantCulture));
            var typeComparison  = Type.CompareTo(categoryObj.Type);
            var topicComparison = Topic.CompareTo(categoryObj.Topic);

            if (nameComparison != 0)
            {
                return(nameComparison);
            }
            if (typeComparison != 0)
            {
                return(typeComparison);
            }
            if (topicComparison != 0)
            {
                return(topicComparison);
            }
            return(0);
        }
 public int CompareTo(GoodNumber other)
 {
     if (MessageType != other.MessageType)
     {
         return(MessageType.CompareTo(other.MessageType));
     }
     return(Number.CompareTo(other.Number));
 }
Beispiel #4
0
 public int CompareTo(object obj)
 {
     if (!(obj is Category category))
     {
         return(1);
     }
     if (ProductName != category.ProductName)
     {
         return(ProductName == null ? -1 : ProductName.CompareTo(category.ProductName));
     }
     if (MessageType != category.MessageType)
     {
         return(MessageType.CompareTo(category.MessageType));
     }
     return(MessageTopic.CompareTo(category.MessageTopic));
 }
        /// <summary>
        /// Выполняет сравнение сначала по тексту сообщения, потом по типу, потом по теме
        /// Позволяет сравнивать так же null - объекты и объекты, содержащие null - поля
        /// </summary>
        public int CompareTo(object obj)
        {
            if ((object)this == null && obj == null)
            {
                return(0);
            }
            if (obj == null)
            {
                return(1);
            }
            if (!(obj is Category))
            {
                throw new ArgumentException();
            }
            if ((object)this == null)
            {
                return(-1);
            }
            sbyte compareResult = 0;

            if ((MessageText == null) != (((Category)obj).MessageText == null))
            {
                return(((Category)obj).MessageText == null ? 1 : -1);
            }
            else if (MessageText != null)
            {
                compareResult = (sbyte)MessageText.CompareTo(((Category)obj).MessageText);
            }
            if (compareResult != 0)
            {
                return(compareResult);
            }
            else
            {
                compareResult = (sbyte)MessageType.CompareTo(((Category)obj).MessageType);
                if (compareResult != 0)
                {
                    return(compareResult);
                }
                else
                {
                    return(MessageTopic.CompareTo(((Category)obj).MessageTopic));
                }
            }
        }
 public int CompareTo(object obj)
 {
     if (obj == null)
     {
         return(1);
     }
     if (obj is Category)
     {
         var cobj   = (Category)obj;
         var n      = Name?.CompareTo(cobj.Name) ?? -1;
         var ty     = Type.CompareTo(cobj.Type);
         var to     = Topic.CompareTo(cobj.Topic);
         var result = n != 0 ? n : (ty != 0 ? ty : to);
         return(result);
     }
     else
     {
         throw new ArgumentException($"Can not compate Category with {obj.GetType().Name}");
     }
 }