Inheritance: DynamicMetaObjectBinder
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            if (Value is SilverInstance) {
                string silverName = InteropBinder.MapExpressionType(binder.Operation);
                if (silverName == null) {
                    return InteropBinder.Binary.Bind(binder, this, arg);
                }

                if (
                    InteropBinder.InvokeMember.SearchForFunction(((SilverInstance) Value).Class, silverName,
                        (SilverInstance) Value, L(Arg(arg.Value)), true) != null) {
                    return
                        InteropBinder.InvokeMember.Bind(
                            new InteropBinder.InvokeMember(silverName, new CallInfo(0), Scope), this,
                            _DMO(DMO(Scope), DMO(Arg(arg.Value))));
                }
                string clrName = InteropBinder.ToClrOperatorName(silverName);
                if (
                    InteropBinder.InvokeMember.SearchForFunction(((SilverInstance) Value).Class, clrName,
                        (SilverInstance) Value, L(Arg(arg.Value)), true) != null) {
                    return
                        InteropBinder.InvokeMember.Bind(
                            new InteropBinder.InvokeMember(clrName, new CallInfo(0), Scope), this,
                            _DMO(DMO(Scope), DMO(Arg(arg.Value))));
                }
                return InteropBinder.Binary.Bind(binder, this, arg);
            }
            return InteropBinder.Binary.Bind(binder, this, arg);
        }
Esempio n. 2
0
        public override Boolean TryBinaryOperation(BinaryOperationBinder binder, Object arg, out Object result)
        {
            switch (binder.Operation) {
                case ExpressionType.GreaterThan:
                case ExpressionType.GreaterThanOrEqual:
                case ExpressionType.LessThan:
                case ExpressionType.LessThanOrEqual: {
                    if (!typeof(IComparable).IsAssignableFrom(_targetType))
                        throw new NotSupportedException(string.Format("Can not perform unary operation '{0}' on type '{1}', is does not implement IComparable", binder.Operation, ReflectionHelper.GetTypeName(_targetType)));

                    var tmp = ((IComparable) _target).CompareTo(arg);
                    result = null;
                    if (binder.Operation == ExpressionType.GreaterThan) result = (tmp > 0);
                    if (binder.Operation == ExpressionType.GreaterThanOrEqual) result = (tmp >= 0);
                    if (binder.Operation == ExpressionType.LessThan) result = (tmp < 0);
                    if (binder.Operation == ExpressionType.LessThanOrEqual) result = (tmp <= 0);
                    return true;
                }

                case ExpressionType.Equal: {
                    result = _target.Equals(arg);
                    return true;
                }
            }

            throw new NotImplementedException(String.Format("TryBinaryOperation op='{0}' arg='{1}'", binder.Operation, arg));
        }
Esempio n. 3
0
        internal override bool BinaryOperation(BinaryOperationBinder binder, Any arg, out Any result)
        {
            var number = arg as Number;
            if (number != null)
            {
                switch (binder.Operation)
                {
                    case ExpressionType.Add:
                        result = new Number(Value + number.Value);
                        break;
                    case ExpressionType.Subtract:
                        result = new Number(Value - number.Value);
                        break;
                    case ExpressionType.Multiply:
                        result = new Number(Value * number.Value);
                        break;
                    case ExpressionType.Divide:
                        result = new Number(Value / number.Value);
                        break;
                    case ExpressionType.LessThan:
                        result = Value < number.Value ? Bool.True : Bool.False;
                        break;
                    case ExpressionType.LessThanOrEqual:
                        result = Value <= number.Value ? Bool.True : Bool.False;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                return true;
            }

            return base.BinaryOperation(binder, arg, out result);
        }
Esempio n. 4
0
 /// <summary>
 /// Provides implementation for binary operations. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as addition and multiplication.
 /// </summary>
 /// <param name="binder">Provides information about the binary operation. The binder.Operation property returns an <see cref="T:System.Linq.Expressions.ExpressionType" /> object. For example, for the sum = first + second statement, where first and second are derived from the DynamicObject class, binder.Operation returns ExpressionType.Add.</param>
 /// <param name="arg">The right operand for the binary operation. For example, for the sum = first + second statement, where first and second are derived from the DynamicObject class, <paramref name="arg" /> is equal to second.</param>
 /// <param name="result">The result of the binary operation.</param>
 /// <returns>
 /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)
 /// </returns>
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     result = null;
     if (binder.Operation == ExpressionType.LeftShift)
     {
         result = ((dynamic)(this))(arg);
         return true;
     }
     return false;
 }
Esempio n. 5
0
		public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
		{
			//--- Debbuger Break --- //
			if(System.Diagnostics.Debugger.IsAttached)
				System.Diagnostics.Debugger.Break();
			//--- Debbuger Break --- //
			bool res = base.TryBinaryOperation(binder, arg, out result);

			return res;
		}
 public override bool TryBinaryOperation(BinaryOperationBinder binder,
                      object arg, out object result)
 {
     bool success = false;
     if (binder.Operation == System.Linq.Expressions.ExpressionType.Add)
     {
         Console.WriteLine("I have to think about that");
         success = true;
     }
     result = this;
     return success;
 }
Esempio n. 7
0
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     if(binder.Operation == ExpressionType.LeftShiftAssign)
     {
         var copy = new ListBag(_dict, _list);
         copy.AddMembersFromObject(arg);
         result = copy;
         return true;
     }
     result = null;
     return false;
 }
Esempio n. 8
0
        /// <summary>
        /// Provides the implementation of performing AddAssign and SubtractAssign binary operations.
        /// </summary>
        /// <param name="binder">The binder provided by the call site.</param>
        /// <param name="handler">The handler for the operation.</param>
        /// <param name="result">The result of the operation.</param>
        /// <returns>true if the operation is complete, false if the call site should determine behavior.</returns>
        public override bool TryBinaryOperation(BinaryOperationBinder binder, object handler, out object result) {
            if (binder.Operation == ExpressionType.AddAssign) {
                result = InPlaceAdd(handler);
                return true;
            }

            if (binder.Operation == ExpressionType.SubtractAssign) {
                result = InPlaceSubtract(handler);
                return true;
            }

            result = null;
            return false;
        }
Esempio n. 9
0
 public override bool TryBinaryOperation( BinaryOperationBinder binder, object arg, out object result )
 {
     if(!ReferenceEquals(Prototype, null))
     {
         if(Prototype.TryBinaryOperation(binder, arg, out result))
         {
             return true;
         }
     }
     if ( TryBinaryOperationMissing == null )
     {
         result = null;
         return false;
     }
     return TryBinaryOperationMissing( binder, arg, out result );
 }
Esempio n. 10
0
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     var str = arg as string;
     if (str != null)
     {
         if (binder.Operation == ExpressionType.Equal)
         {
             result = node.Value == str;
             return true;
         }
         if (binder.Operation == ExpressionType.NotEqual)
         {
             result = node.Value != str;
             return true;
         }
     }
     return base.TryBinaryOperation(binder, arg, out result);
 }
Esempio n. 11
0
        internal override bool BinaryOperation(BinaryOperationBinder binder, Any arg, out Any result)
        {
            var str = arg as String;
            if (str != null)
            {
                switch (binder.Operation)
                {
                    case ExpressionType.Add:
                        result = new String(Value + str.Value);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }

                return true;
            }

            return base.BinaryOperation(binder, arg, out result);
        }
Esempio n. 12
0
            public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
            {
                /* Effectively returns the following code:
                 * {
                 *      var thisEvaled = (JsonObject)<Expression>;
                 *      object res;
                 *      ReturnType finalResult;
                 *      if(!Value.InnerTryBinaryOperations(Operand, arg, ReturnType, out res))
                 *      {
                 *          throw new InvalidCastException("Unable to invoke dynamic binary operation [<Operation>] on ["+thisRef+"]");
                 *      }
                 *      finalResult = (ReturnType)res;
                 * }
                 */

                var thisRef = Expression.Type != typeof(JsonObject) ? Expression.Convert(Expression, typeof(JsonObject)) : Expression;
                var thisEvaled = ThisEvaled;
                var thisAssigned = Expression.Assign(thisEvaled, thisRef);
                var finalResult = Expression.Variable(binder.ReturnType);
                var argRef = ArgRef;
                var argAssigned = Expression.Assign(argRef, (arg.RuntimeType == null || arg.RuntimeType.IsValueType()) ? Expression.Convert(arg.Expression, typeof(object)) : arg.Expression);
                var res = Res;
                var tryInvokeMemberCall = Expression.Call(thisEvaled, InnerTryBinaryOperation, Expression.Constant(binder.Operation), argRef, Expression.Constant(binder.ReturnType), res);
                var throwExc =
                    Expression.Throw(
                        Expression.New(
                            InvalidCastExceptionCons,
                            Expression.Call(
                                StringConcat,
                                Expression.Constant("Unable to invoke dynamic binary operation [" + binder.Operation + "] on ["),
                                thisEvaled,
                                CloseSquareBracket
                            )
                        )
                    );

                var notIf =
                    Expression.IfThen(
                        Expression.Not(tryInvokeMemberCall),
                        throwExc
                    );
                var finalAssign = Expression.Assign(finalResult, Expression.Convert(res, binder.ReturnType));

                var retBlock = Expression.Block(new[] { thisEvaled, finalResult, res, argRef }, thisAssigned, argAssigned, notIf, finalAssign);
                var restrictions = BindingRestrictions.GetTypeRestriction(Expression, LimitType);

                return new DynamicMetaObject(retBlock, restrictions);
            }
Esempio n. 13
0
 /// <summary>
 ///     Performs the binding of the dynamic binary operation.
 /// </summary>
 /// <param name="binder">
 ///     An instance of the <see cref="BinaryOperationBinder" /> that represents the details of the dynamic
 ///     operation.
 /// </param>
 /// <param name="arg">
 ///     An instance of the <see cref="DynamicMetaObject" /> representing the right hand side of the binary
 ///     operation.
 /// </param>
 /// <returns>The new <see cref="DynamicMetaObject" /> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     ContractUtils.RequiresNotNull(binder, nameof(binder));
     return(binder.FallbackBinaryOperation(this, arg));
 }
Esempio n. 14
0
            public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) {
                if (IsOverridden("TryBinaryOperation")) {
                    return CallMethodWithResult("TryBinaryOperation", binder, DynamicMetaObject.GetExpressions(new DynamicMetaObject[] {arg}), (e) => binder.FallbackBinaryOperation(this, arg, e));
                }

                return base.BindBinaryOperation(binder, arg);
            }
    public virtual new bool TryBinaryOperation(BinaryOperationBinder binder, Object arg, out Object result)
    {
      result = default(Object);

      return default(bool);
    }
Esempio n. 16
0
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     return base.TryBinaryOperation(binder, arg, out result);
 }
Esempio n. 17
0
 /// <summary>
 /// Override on DynamicObject
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="arg"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     result = new Mimic();
     return true;
 }
Esempio n. 18
0
		public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
		{
			if (binder.Operation == ExpressionType.Equal)
			{
				var wrapper = this.Value as ExpressionContainer;
				var valueExpr = wrapper.Expression as MemberExpression;
				if (valueExpr != null)
				{
					var prevContainer = new ExpressionContainer(valueExpr.Expression) { IsStatic = ((PropertyInfo)valueExpr.Member).GetGetMethod(true).IsStatic };
					return DoBindSetMember(prevContainer, binder.ReturnType, valueExpr.Member.Name, false, arg);
				}
			}

			return base.BindBinaryOperation(binder, arg);
		}
Esempio n. 19
0
 public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     throw new NotImplementedException();
 }
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     result = MakeBinaryBuilder(Expression, binder.Operation, arg);
     return true;
 }
Esempio n. 21
0
        private DispatchResult DispatchBinaryOperation(BinaryOperationBinder binder, Object arg1, Object arg2)
        {
            var old_value = Value;
            Value = arg1;

            try
            {
                try
                {
                    try
                    {
                        var result = BinaryOperation(binder, arg2);
                        if (result is FallbackException) throw (FallbackException)result;
                        return Succeed(result);
                    }
                    catch (FallbackException)
                    {
                        var dynamic_object = Value as IDynamicObject;
                        if (dynamic_object != null) return Succeed(dynamic_object.BinaryOperation(binder, arg2));
                        else throw;
                    }
                }
                catch (FallbackException)
                {
                    return Fail();
                }
                catch (Exception ex)
                {
                    if (WrapExceptions)
                    {
                        var bind_args = new OrderedDictionary<String, Object>();
                        bind_args.Add("arg1", arg1);
                        bind_args.Add("arg2", arg2);
                        throw new BindException(binder, bind_args, ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                Value = old_value;
            }
        }
Esempio n. 22
0
        public sealed override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            var fallback = ((Func<Expression>)(() =>
            {
                try { return base.BindBinaryOperation(binder, arg).Expression; }
                catch (Exception ex) { return Expression.Throw(Expression.Constant(ex)); }
            }))();

            var dispatchResult = Expression.Parameter(typeof(DispatchResult), "dispatchResult");
            var shim = Expression.Block(dispatchResult.MkArray(),
                // 1. var dispatchResult = DispatchBinaryOperation(binder, `expression`, arg);
                Expression.Assign(dispatchResult, Expression.Call(
                    Expression.Constant(this),
                    typeof(SimpleMetaObject).GetMethod("DispatchBinaryOperation", BF.PrivateInstance),
                    Expression.Constant(binder),
                    Expression,
                    Expression.Convert(arg.Expression, typeof(Object)))),
                // 2. return dispatchResult.Success ? dispatchResult.Result : `fallback`;
                Expression.Condition(
                    Expression.Property(dispatchResult, "Success"),
                    Expression.Convert(Expression.Property(dispatchResult, "Result"), binder.ReturnType),
                    fallback,
                    binder.ReturnType));
            return new DynamicMetaObject(shim, BindingRestrictions.GetTypeRestriction(Expression, LimitType));
        }
Esempio n. 23
0
 public virtual Object BinaryOperation(BinaryOperationBinder binder, Object arg) { throw Fallback(); }
Esempio n. 24
0
 /// <summary>
 /// Performs the binding of the dynamic binary operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="BinaryOperationBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="arg">An instance of the <see cref="DynamicMetaObject"/> representing the right hand side of the binary operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackBinaryOperation(this, arg);
 }
 /// <summary>
 /// Forwards the Binary operation
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="arg"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     result = null;
     try
     {
         result = Impromptu.InvokeBinaryOperator(CallTarget, binder.Operation, arg);
         return true;
     }
     catch (RuntimeBinderException)
     {
         return false;
     }
 }
Esempio n. 26
0
 public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     return scriptItem.PostProcessBindResult(metaDynamic.BindBinaryOperation(binder, arg));
 }
Esempio n. 27
0
        public virtual new System.Dynamic.DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, System.Dynamic.DynamicMetaObject arg)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }
Esempio n. 28
0
 public override Boolean TryBinaryOperation(BinaryOperationBinder binder, Object arg, out Object result)
 {
     throw new NotImplementedException("JsStore.TryBinaryOperation");
 }
        public virtual new bool TryBinaryOperation(BinaryOperationBinder binder, Object arg, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }
		public override bool TryBinaryOperation (BinaryOperationBinder binder, object arg, out object result)
		{
			Console.WriteLine ("System.Windows.Interop.ComAutomationEventMetaObjectProvider.TryBinaryOperation: NIEX");
			throw new NotImplementedException ();
		}
Esempio n. 31
0
        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;
        }
Esempio n. 32
0
        public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
        {
            switch (binder.Operation)
            {
                case ExpressionType.Equal:
                    result = ReferenceEquals(arg, Nil.Instance) || (object)arg == null;
                    return true;
                case ExpressionType.NotEqual:
                    result = !ReferenceEquals(arg, Nil.Instance) && (object)arg != null;
                    return true;
            }

            return base.TryBinaryOperation(binder, arg, out result);
        }
Esempio n. 33
0
 public virtual bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) {
     result = null;
     return false;
 }
 //
 // Summary:
 //     Provides implementation for binary operations. Classes derived from the System.Dynamic.DynamicObject
 //     class can override this method to specify dynamic behavior for operations such
 //     as addition and multiplication.
 //
 // Parameters:
 //   binder:
 //     Provides information about the binary operation. The binder.Operation property
 //     returns an System.Linq.Expressions.ExpressionType object. For example, for the
 //     sum = first + second statement, where first and second are derived from the DynamicObject
 //     class, binder.Operation returns ExpressionType.Add.
 //
 //   arg:
 //     The right operand for the binary operation. For example, for the sum = first
 //     + second statement, where first and second are derived from the DynamicObject
 //     class, arg is equal to second.
 //
 //   result:
 //     The result of the binary operation.
 //
 // Returns:
 //     true if the operation is successful; otherwise, false. If this method returns
 //     false, the run-time binder of the language determines the behavior. (In most
 //     cases, a language-specific run-time exception is thrown.)
 public virtual bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result);
Esempio n. 35
0
 /*!*/
 public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder/*!*/ binder, DynamicMetaObject/*!*/ arg)
 {
     return InteropBinder.BinaryOperation.Bind(CreateMetaContext(), binder, this, arg, binder.FallbackBinaryOperation);
 }
Esempio n. 36
0
 public virtual bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
 {
     result = null;
     return(false);
 }