示例#1
0
        public object CompareTo(object other)
        {
            IDictionary <object, object> oth = other as IDictionary <object, object>;

            // CompareTo is allowed to throw (string, int, etc... all do it if they don't get a matching type)
            if (oth == null)
            {
                object len, iteritems;
                if (!Ops.TryGetAttr(other, SymbolTable.Length, out len) ||
                    !Ops.TryGetAttr(other, SymbolTable.StringToId("iteritems"), out iteritems))
                {
                    return(Ops.NotImplemented);
                }

                // user-defined dictionary...
                int lcnt = this.Count;
                int rcnt = Converter.ConvertToInt32(Ops.Call(len));

                if (lcnt != rcnt)
                {
                    return(lcnt > rcnt ? 1 : -1);
                }


                return(DictOps.CompareToWorker(this, rcnt, new List(Ops.Call(iteritems))));
            }

            return(DictOps.CompareTo(this, oth));
        }
示例#2
0
        int IComparable.CompareTo(object obj)
        {
            IDictionary <object, object> other = obj as IDictionary <object, object>;

            // CompareTo is allowed to throw (string, int, etc... all do it if they don't get a matching type)
            if (other == null)
            {
                throw Ops.TypeError("CompareTo argument must be a Dictionary");
            }

            return(DictOps.CompareTo(this, other));
        }