Represents the unary dynamic operation at the call site, providing the binding semantic and the details about the operation.
Inheritance: DynamicMetaObjectBinder
Ejemplo n.º 1
0
        public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
        {
            if (binder.Operation != ExpressionType.OnesComplement)
            {
                return base.TryUnaryOperation(binder, out result);
            }

            result = get_xml_value();
            return true;
        }
Ejemplo n.º 2
0
        internal override bool UnaryOperation(UnaryOperationBinder binder, out Any result)
        {
            switch (binder.Operation)
            {
                case ExpressionType.IsTrue:
                    result = Value.Length > 0 ? Bool.True : Bool.False;
                    return true;
            }

            return base.UnaryOperation(binder, out result);
        }
Ejemplo n.º 3
0
        internal override bool UnaryOperation(UnaryOperationBinder binder, out Any result)
        {
            switch (binder.Operation)
            {
                case ExpressionType.IsTrue:
                    result = ((int)Value) != 0 ? Bool.True : Bool.False;
                    return true;
                case ExpressionType.Negate:
                    result = new Number(-Value);
                    return true;
            }

            return base.UnaryOperation(binder, out result);
        }
Ejemplo n.º 4
0
 public override bool TryUnaryOperation(UnaryOperationBinder binder, out Object result)
 {
     int r;
     IntPtr res;
     switch (binder.Operation)
     {
     case ExpressionType.Negate:
         res = Runtime.PyNumber_Negative(this.obj);
         break;
     case ExpressionType.UnaryPlus:
         res = Runtime.PyNumber_Positive(this.obj);
         break;
     case ExpressionType.OnesComplement:
         res = Runtime.PyNumber_Invert(this.obj);
         break;
     case ExpressionType.Not:
         r = Runtime.PyObject_Not(this.obj);
         result = r == 1;
         return r != -1;
     case ExpressionType.IsFalse:
         r = Runtime.PyObject_IsTrue(this.obj);
         result = r == 0;
         return r != -1;
     case ExpressionType.IsTrue:
         r = Runtime.PyObject_IsTrue(this.obj);
         result = r == 1;
         return r != -1;
     case ExpressionType.Decrement:
     case ExpressionType.Increment:
     default:
         result = null;
         return false;
     }
     result = new PyObject(res);
     return true;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Override on DynamicObject
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
 {
     result = new Mimic();
     return true;
 }
Ejemplo n.º 6
0
		public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
		{
			if(binder.Operation == System.Linq.Expressions.ExpressionType.IsTrue)
			{
			 result = this;
				return true;
			}
			throw new NotImplementedException();
			
		}
Ejemplo n.º 7
0
        public override Boolean TryUnaryOperation(UnaryOperationBinder binder, out Object result)
        {
            result = null;
            Boolean boolResult;

            switch (binder.Operation) {
                case ExpressionType.IsTrue: {
                    if (TypeConversion.TryConvertTo(_target, out boolResult)) {
                        result = boolResult;
                        return true;
                    }
                    return false;
                }
            }

            throw new NotImplementedException(String.Format("TryUnaryOperation op={0}", binder.Operation));
        }
Ejemplo n.º 8
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.º 9
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return scriptItem.PostProcessBindResult(metaDynamic.BindUnaryOperation(binder));
 }
Ejemplo n.º 10
0
 /*!*/
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder/*!*/ binder)
 {
     return InteropBinder.UnaryOperation.Bind(CreateMetaContext(), binder, this, binder.FallbackUnaryOperation);
 }
Ejemplo n.º 11
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return BuildCallSelf(_unaryMethod, Expression.Constant(binder.Operation));
 }
        public virtual new bool TryUnaryOperation(UnaryOperationBinder binder, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }
Ejemplo n.º 14
0
 public override bool TryUnaryOperation( UnaryOperationBinder binder, out object result )
 {
     if ( TryUnaryOperationMissing == null )
     {
         result = null;
         return false;
     }
     return TryUnaryOperationMissing( binder, out result );
 }
Ejemplo n.º 15
0
 public virtual bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
 {
     result = null;
     return(false);
 }
Ejemplo n.º 16
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, nameof(binder));
     return(binder.FallbackUnaryOperation(this));
 }
Ejemplo n.º 17
0
 public virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 18
0
 //
 // Summary:
 //     Provides implementation for unary operations. Classes derived from the System.Dynamic.DynamicObject
 //     class can override this method to specify dynamic behavior for operations such
 //     as negation, increment, or decrement.
 //
 // Parameters:
 //   binder:
 //     Provides information about the unary operation. The binder.Operation property
 //     returns an System.Linq.Expressions.ExpressionType object. For example, for the
 //     negativeNumber = -number statement, where number is derived from the DynamicObject
 //     class, binder.Operation returns "Negate".
 //
 //   result:
 //     The result of the unary 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 TryUnaryOperation(UnaryOperationBinder binder, out object result);
Ejemplo n.º 19
0
		public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
		{
			if (binder.Operation != ExpressionType.OnesComplement)
			{
				return base.TryUnaryOperation(binder, out result);
			}

			result = (_nodeType == NodeType.Element) ? InternalContent : InternalValue;

			return true;
		}
        public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
        {
            if (binder.Operation == ExpressionType.IsFalse || binder.Operation == ExpressionType.IsTrue)
            {
                result = false;
                return true;
            }

            result = new DynamicExpressionBuilder(Expression.MakeUnary(binder.Operation, Expression, binder.ReturnType));
            return true;
        }
Ejemplo n.º 21
0
 public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
 {
     MessageBox.Show("Here");
     return base.TryUnaryOperation(binder, out result);
 }
Ejemplo n.º 22
0
        public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
        {
            var eng = GetEngine();

            switch (binder.Operation)
            {
                case ExpressionType.IsFalse:
                    result = !IsTruthy;
                    return true;
                case ExpressionType.IsTrue:
                    result = IsTruthy;
                    return true;

                case ExpressionType.Negate:
                case ExpressionType.NegateChecked:
                    switch (Type)
                    {
                        case JavaScriptValueType.Number:
                            double n = eng.Converter.ToDouble(this);
                            result = -n;
                            return true;

                        case JavaScriptValueType.Boolean:
                            if (IsTruthy)
                                result = -1;
                            else
                                result = -0;
                            return true;
                            
                        // TODO
                        // case JavaScriptValueType.String:
                    }

                    result = double.NaN;
                    return true;

                case ExpressionType.UnaryPlus:
                    switch (Type)
                    {
                        case JavaScriptValueType.Number:
                            result = eng.Converter.ToDouble(this);
                            return true;

                        case JavaScriptValueType.Boolean:
                            if (IsTruthy)
                                result = 1;
                            else
                                result = 0;

                            return true;
                    }

                    result = double.NaN;
                    return true;
            }

            return base.TryUnaryOperation(binder, out result);
        }
    public virtual new System.Dynamic.DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
    {
      Contract.Requires(binder != null);

      return default(System.Dynamic.DynamicMetaObject);
    }
Ejemplo n.º 24
0
 public override Boolean TryUnaryOperation(UnaryOperationBinder binder, out Object result)
 {
     throw new NotImplementedException("JsValue.TryUnaryOperation");
 }
Ejemplo n.º 25
0
 public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
 {
     return binder.FallbackUnaryOperation(this);
 }
Ejemplo n.º 26
0
            public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
            {
                /*
                 * Effectively returns the following code:
                 * {
                 *      var thisEvaled = (JsonObject)<Expression>;
                 *      object res;
                 *      ReturnType finalResult;
                 *      if(!Value.InnerTryUnaryOperation(ExpressionType, ReturnType, out res))
                 *      {
                 *          throw new InvalidCastException("Unable to get dynamic member <MemberName> of type <ReturnType> from ["+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 res = Res;
                var tryUnaryOperationCall = Expression.Call(thisEvaled, InnerTryUnaryOperation, Expression.Constant(binder.Operation), Expression.Constant(binder.ReturnType), res);
                var throwExc =
                    Expression.Throw(
                        Expression.New(
                            InvalidCastExceptionCons,
                            Expression.Call(
                                StringConcat,
                                Expression.Constant("Unable to perform dynamic unary operation [" + binder.Operation + "] of type [" + binder.ReturnType.FullName + "] from ["),
                                thisEvaled,
                                CloseSquareBracket
                            )
                        )
                    );

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

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

                return new DynamicMetaObject(retBlock, restrictions);
            }
		public virtual bool TryUnaryOperation (UnaryOperationBinder binder, out object result)
		{
			Console.WriteLine ("System.Windows.Interop.ComAutomationMetaObjectProviderBase.TryUnaryOperation: NIEX");
			throw new NotImplementedException ();
		}
Ejemplo n.º 28
0
 /// <summary>
 /// Forwards the unary operation.
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
 {
     result = null;
     try
     {
         result = Impromptu.InvokeUnaryOperator(binder.Operation, CallTarget);
         return true;
     }
     catch (RuntimeBinderException)
     {
         return false;
     }
 }
Ejemplo n.º 29
0
 public virtual bool TryUnaryOperation(UnaryOperationBinder binder, out object result) {
     result = null;
     return false;
 }
Ejemplo n.º 30
0
 public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
 {
     return base.TryUnaryOperation(binder, out result);
 }
Ejemplo n.º 31
0
        public virtual new System.Dynamic.DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }
    public virtual new bool TryUnaryOperation(UnaryOperationBinder binder, out Object result)
    {
      result = default(Object);

      return default(bool);
    }
Ejemplo n.º 33
0
        private DispatchResult DispatchUnaryOperation(UnaryOperationBinder binder, Object arg1)
        {
            var old_value = Value;
            Value = arg1;

            try
            {
                try
                {
                    try
                    {
                        var result = UnaryOperation(binder);
                        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.UnaryOperation(binder));
                        else throw;
                    }
                }
                catch (FallbackException)
                {
                    return Fail();
                }
                catch (Exception ex)
                {
                    if (WrapExceptions)
                    {
                        var bind_args = new OrderedDictionary<String, Object>();
                        bind_args.Add("arg1", arg1);
                        throw new BindException(binder, bind_args, ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                Value = old_value;
            }
        }
Ejemplo n.º 34
0
        public sealed override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            var fallback = ((Func<Expression>)(() =>
            {
                try { return base.BindUnaryOperation(binder).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 = DispatchUnaryOperation(binder, `expression`);
                Expression.Assign(dispatchResult, Expression.Call(
                    Expression.Constant(this),
                    typeof(SimpleMetaObject).GetMethod("DispatchUnaryOperation", BF.PrivateInstance),
                    Expression.Constant(binder),
                    Expression)),
                // 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));
        }
Ejemplo n.º 35
0
 /// <summary>
 ///     Provides the implementation of performing a unary operation.  Derived classes can
 ///     override this method to customize behavior.  When not overridden the call site requesting
 ///     the binder determines the behavior.
 /// </summary>
 /// <param name="binder">The binder provided by the call site.</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 virtual bool TryUnaryOperation(UnaryOperationBinder binder, [NotNullWhen(true)] out object?result)
 {
     No.Op(binder);
     result = null;
     return(false);
 }
Ejemplo n.º 36
0
            public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) {
                if (IsOverridden("TryUnaryOperation")) {
                    return CallMethodWithResult("TryUnaryOperation", binder, NoArgs, (e) => binder.FallbackUnaryOperation(this, e));
                }

                return base.BindUnaryOperation(binder);
            }
Ejemplo n.º 37
0
 public virtual Object UnaryOperation(UnaryOperationBinder binder){ throw Fallback(); }