public int Compare(object obj1, object obj2)
        {
            ItemType type1 = ItemTypeHelper.GetItemType(obj1);
            ItemType type2 = ItemTypeHelper.GetItemType(obj2);

            int cmp = type1.CompareTo(type2);

            if (cmp != 0)
            {
                return(cmp);
            }

            switch (type1)
            {
            case ItemType.NoValue:
            case ItemType.Null:
                return(0);

            case ItemType.Bool:
                return(Comparer <bool> .Default.Compare((bool)obj1, (bool)obj2));

            case ItemType.Number:
                return(Comparer <double> .Default.Compare(
                           Convert.ToDouble(obj1, CultureInfo.InvariantCulture),
                           Convert.ToDouble(obj2, CultureInfo.InvariantCulture)));

            case ItemType.String:
                return(string.CompareOrdinal((string)obj1, (string)obj2));

            default:
                string errorMessage = string.Format(CultureInfo.InvariantCulture, "Unexpected type: {0}", type1);
                Debug.Assert(false, errorMessage);
                throw new InvalidCastException(errorMessage);
            }
        }
示例#2
0
        public int CompareTo(ItemBase other)
        {
            int result = Type.CompareTo(other.Type);

            if (result == 0)
            {
                result = Name.CompareTo(other.Name);
            }
            if (result == 0)
            {
                result = Rarity.CompareTo(other.Rarity);
            }
            if (result == 0)
            {
                result = Compare(other);
            }

            return(result);
        }
示例#3
0
 public int CompareTo(MetaQueryHolder metaQueryHolder)
 {
     if (metaQueryHolder == null)
     {
         return(1);
     }
     if (ItemType != metaQueryHolder.ItemType)
     {
         return(ItemType.CompareTo(metaQueryHolder.ItemType));
     }
     else
     {
         if (QueryType == OPERATION_TYPE_ADD)
         {
             return(1);
         }
         if (QueryType == OPERATION_TYPE_DELETE)
         {
             return(-1);
         }
         return(0);
     }
 }
示例#4
0
 public int CompareTo(ItemKey o) => Nest(Type.CompareTo(o.Type), ID.CompareTo(o.ID));