public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return(IsOverridden(nameof(DynamicProxy <T> .TryUnaryOperation))
       ? CallMethodWithResult(
                nameof(DynamicProxy <T> .TryUnaryOperation),
                binder,
                NoArgs,
                e => binder.FallbackUnaryOperation(this, e)
                )
       : base.BindUnaryOperation(binder));
 }
Ejemplo n.º 2
0
        public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            if (IsOverridden("TryUnaryOperation"))
            {
                return(CallMethodWithResult("TryUnaryOperation", binder, NoArgs, (e) => binder.FallbackUnaryOperation(this, e)));
            }

            return(base.BindUnaryOperation(binder));
        }
        public static DynamicMetaObject Operation(UnaryOperationBinder operation, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
        {
            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Fallback UnaryOperator " + " " + operation.Operation + " " + arg.LimitType.FullName);
            PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, operation.Operation.ToString());

            DynamicMetaObject[] args = new[] { arg };
            if (arg.NeedsDeferral())
                return operation.Defer(arg);

            ValidationInfo valInfo = BindingHelpers.GetValidationInfo(args);

            TotemOperationKind? toOperator = null;
            Type retType = typeof(object);
            bool box = true;
            bool inverse = false;
            switch (operation.Operation)
            {
                case ExpressionType.UnaryPlus: toOperator = TotemOperationKind.Positive; break;
                case ExpressionType.Negate: toOperator = TotemOperationKind.Negate; break;
                case ExpressionType.OnesComplement: toOperator = TotemOperationKind.OnesComplement; break;
                case ExpressionType.Not: toOperator = TotemOperationKind.Not; box = false; break;
                case ExpressionType.IsFalse: toOperator = TotemOperationKind.IsFalse; box = false; retType = typeof(bool); break;
                case ExpressionType.IsTrue: toOperator = TotemOperationKind.IsFalse; box = false; retType = typeof(bool); inverse = true; break;
            }

            DynamicMetaObject res = null;
            if (toOperator != null)
                res = MakeUnaryOperation(operation, args[0], toOperator.Value, errorSuggestion, retType);
            else
                res = operation.FallbackUnaryOperation(arg);

            if (inverse)
            {
                res = new DynamicMetaObject(
                    Expression.Condition(
                        res.Expression,
                        Utils.Constant(ScriptingRuntimeHelpers.False),
                        Utils.Constant(ScriptingRuntimeHelpers.True)
                    ),
                    res.Restrictions
                );
            }

            if (box)
            {
                res = BindingHelpers.AddTotemBoxing(res);
            }

            return BindingHelpers.AddDynamicTestAndDefer(operation, res, args, valInfo, retType);
        }
Ejemplo n.º 4
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return(_runtime.TryUnaryOperation != null
          ? CallMethodWithResult("TryUnaryOperation", binder, NoArgs, e => binder.FallbackUnaryOperation(this, e))
          : base.BindUnaryOperation(binder));
 }
Ejemplo n.º 5
0
        public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            DynamicMetaObject messageSendMO;
            Expression        value;
            DynamicMetaObject arg;

            switch (binder.Operation)
            {
            case ExpressionType.Negate:
                if (createMetaObjectToSendMessage("negated", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.UnaryPlus:
                if (createMetaObjectToSendMessage("abs", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Not:
                if (createMetaObjectToSendMessage("not", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Decrement:
                if (createMetaObjectToSendMessage("decrement", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Increment:
                if (createMetaObjectToSendMessage("increment", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.OnesComplement:
                if (createMetaObjectToSendMessage("bitInvert", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.IsTrue:
                value = Expression.Constant(true);
                arg   = value.asDynamicMetaObject(BindingRestrictions.Empty, true);
                if (createMetaObjectToSendMessage("=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.IsFalse:
                value = Expression.Constant(false);
                arg   = value.asDynamicMetaObject(BindingRestrictions.Empty, false);
                if (createMetaObjectToSendMessage("=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            default:
            case ExpressionType.Extension:
                messageSendMO = null;
                break;
            }

            if (messageSendMO == null)
            {
                var esClass  = ValueClass;
                var kernel   = esClass.ObjectSpace;
                var selector = kernel.symbolFor("??");
                messageSendMO = metaObjectToSendDoesNotUnderstand(selector, DynamicBindingGuru.emptyArgArray);
            }
            return(binder.FallbackUnaryOperation(this, messageSendMO));
        }
Ejemplo n.º 6
0
 public override DynamicMetaObject _0001(UnaryOperationBinder key)
 {
     //Discarded unreachable code: IL_0002
     //IL_0003: Incompatible stack heights: 0 vs 1
     if (!CancelProperty("TryUnaryOperation"))
     {
         return(base.BindUnaryOperation(key));
     }
     return(DefineProperty("TryUnaryOperation", key, WorkerClientBridge <T> ._0001(), (DynamicMetaObject P_0) => key.FallbackUnaryOperation(this, P_0)));
 }
            public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) {
                if (IsOverridden("TryUnaryOperation")) {
                    return CallMethodWithResult("TryUnaryOperation", binder, NoArgs, (e) => binder.FallbackUnaryOperation(this, e));
                }

                return base.BindUnaryOperation(binder);
            }
 /// <summary>
 /// Performs the binding of the dynamic unary operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="UnaryOperationBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackUnaryOperation(this);
 }
Ejemplo n.º 9
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     if (!this.IsOverridden("TryUnaryOperation"))
     {
         return(base.BindUnaryOperation(binder));
     }
     return(this.CallMethodWithResult("TryUnaryOperation", binder, DynamicProxyMetaObject <T> .NoArgs, (DynamicMetaObject e) => binder.FallbackUnaryOperation(this, e), null));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Performs the binding of the dynamic unary operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="UnaryOperationBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackUnaryOperation(this));
 }
Ejemplo n.º 11
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return(binder.FallbackUnaryOperation(_baseMetaObject,
                                          AddTypeRestrictions(_metaObject.BindUnaryOperation(binder))));
 }