コード例 #1
0
ファイル: Dict.cs プロジェクト: weimingtom/IronPythonMod
        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));
        }