当前位置: 首页>>代码示例>>C#>>正文


C# Object.ToPython方法代码示例

本文整理汇总了C#中System.Object.ToPython方法的典型用法代码示例。如果您正苦于以下问题:C# Object.ToPython方法的具体用法?C# Object.ToPython怎么用?C# Object.ToPython使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Object的用法示例。


在下文中一共展示了Object.ToPython方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryBinaryOperation

        public override bool TryBinaryOperation(BinaryOperationBinder binder, Object arg, out Object result)
        {
            IntPtr res;
            if (!(arg is PyObject))
            arg = arg.ToPython();

            switch (binder.Operation)
            {
            case ExpressionType.Add:
                res = Runtime.PyNumber_Add(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.AddAssign:
                res = Runtime.PyNumber_InPlaceAdd(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.Subtract:
                res = Runtime.PyNumber_Subtract(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.SubtractAssign:
                res = Runtime.PyNumber_InPlaceSubtract(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.Multiply:
                res = Runtime.PyNumber_Multiply(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.MultiplyAssign:
                res = Runtime.PyNumber_InPlaceMultiply(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.Divide:
                res = Runtime.PyNumber_Divide(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.DivideAssign:
                res = Runtime.PyNumber_InPlaceDivide(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.And:
                res = Runtime.PyNumber_And(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.AndAssign:
                res = Runtime.PyNumber_InPlaceAnd(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.ExclusiveOr:
                res = Runtime.PyNumber_Xor(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.ExclusiveOrAssign:
                res = Runtime.PyNumber_InPlaceXor(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.GreaterThan:
                result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) > 0;
                return true;
            case ExpressionType.GreaterThanOrEqual:
                result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) >= 0;
                return true;
            case ExpressionType.LeftShift:
                res = Runtime.PyNumber_Lshift(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.LeftShiftAssign:
                res = Runtime.PyNumber_InPlaceLshift(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.LessThan:
                result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) < 0;
                return true;
            case ExpressionType.LessThanOrEqual:
                result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) <= 0;
                return true;
            case ExpressionType.Modulo:
                res = Runtime.PyNumber_Remainder(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.ModuloAssign:
                res = Runtime.PyNumber_InPlaceRemainder(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.NotEqual:
                result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) != 0;
                return true;
            case ExpressionType.Or:
                res = Runtime.PyNumber_Or(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.OrAssign:
                res = Runtime.PyNumber_InPlaceOr(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.Power:
                res = Runtime.PyNumber_Power(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.RightShift:
                res = Runtime.PyNumber_Rshift(this.obj, ((PyObject)arg).obj);
                break;
            case ExpressionType.RightShiftAssign:
                res = Runtime.PyNumber_InPlaceRshift(this.obj, ((PyObject)arg).obj);
                break;
            default:
                result = null;
                return false;
            }
            result = new PyObject(res);
            return true;
        }
开发者ID:patstew,项目名称:pythonnet_old,代码行数:93,代码来源:pyobject.cs


注:本文中的System.Object.ToPython方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。