コード例 #1
0
ファイル: OldInstance.cs プロジェクト: wangpei421/ironpython2
        public object __cmp__(CodeContext context, object other)
        {
            OldInstance oiOther = other as OldInstance;

            // CPython raises this if called directly, but not via cmp(os,ns) which still calls the user __cmp__
            //if(!(oiOther is OldInstance))
            //    throw Ops.TypeError("instance.cmp(x,y) -> y must be an instance, got {0}", Ops.StringRepr(DynamicHelpers.GetPythonType(other)));

            object res = InternalCompare("__cmp__", other);

            if (res != NotImplementedType.Value)
            {
                return(res);
            }
            if (oiOther != null)
            {
                res = oiOther.InternalCompare("__cmp__", this);
                if (res != NotImplementedType.Value)
                {
                    return(((int)res) * -1);
                }
            }

            return(NotImplementedType.Value);
        }
コード例 #2
0
ファイル: OldInstance.cs プロジェクト: wangpei421/ironpython2
        private object CompareForwardReverse(object other, string forward, string reverse)
        {
            object res = InternalCompare(forward, other);

            if (res != NotImplementedType.Value)
            {
                return(res);
            }

            OldInstance oi = other as OldInstance;

            if (oi != null)
            {
                // comparison operators are reflexive
                return(oi.InternalCompare(reverse, this));
            }

            return(NotImplementedType.Value);
        }