public static void TestBindParams(DynamicMetaObject target)
            {
                GetIndexBinder binder         = new TestGetIndexBinder();
                Expression     typeExpression = Expression.Parameter(typeof(int));

                DynamicMetaObject[] indexes =
                {
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 0),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 1),
                    new DynamicMetaObject(typeExpression, BindingRestrictions.Empty, 2)
                };

                ExceptionHelper.Throws <ArgumentNullException>(() => { var result = target.BindGetIndex(null, indexes); });
                ExceptionHelper.Throws <ArgumentNullException>(() => { var result = target.BindGetIndex(binder, null); });

                DynamicMetaObject[][] invalidIndexesParam =
                {
                    indexes,
                    new DynamicMetaObject[] { new DynamicMetaObject(typeExpression,BindingRestrictions.Empty,                                                         null) },
                    new DynamicMetaObject[] { null },
                    new DynamicMetaObject[] { }
                };

                foreach (DynamicMetaObject[] indexesParam in invalidIndexesParam)
                {
                    DynamicMetaObject metaObj = target.BindGetIndex(binder, indexesParam);

                    Expression <Action> expression = Expression.Lambda <Action>(Expression.Block(metaObj.Expression), new ParameterExpression[] { });
                    ExceptionHelper.Throws <ArgumentException>(() => { expression.Compile().Invoke(); }, NonSingleNonNullIndexNotSupported);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the binding of the dynamic get index operation.
        /// </summary>
        /// <param name="target">The target of the dynamic get index operation.</param>
        /// <param name="args">An array of arguments of the dynamic get index operation.</param>
        /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
        public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
        {
            ContractUtils.RequiresNotNull(target, "target");
            ContractUtils.RequiresNotNullItems(args, "args");

            return(target.BindGetIndex(this, args));
        }
Exemplo n.º 3
0
        private static object GetIndex(this DynamicMetaObject target, object[] indices)
        {
            var paramNames = Enumerable.Range(0, indices.Length).Select(index => "a" + index).ToArray();
            var paramExprs = paramNames.Select((paramName, index) => Expression.Parameter(GetParamTypeForArg(indices[index]), paramName)).ToArray();
            var parameters = paramExprs.Select(paramExpr => new DynamicMetaObject(paramExpr, BindingRestrictions.Empty)).ToArray();
            var bindResult = target.BindGetIndex(new DynamicGetIndexBinder(paramNames), parameters);
            var block      = Expression.Block(Expression.Label(CallSiteBinder.UpdateLabel), bindResult.Expression);

            return(Invoke(block, paramExprs, indices));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Tries to perform binding of the dynamic get index operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetIndexBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="instance">The target of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
 /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param>
 /// <returns>True if operation was bound successfully; otherwise, false.</returns>
 public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
 {
     if (TryGetMetaObjectInvoke(ref instance))
     {
         result = instance.BindGetIndex(binder, args);
         return(true);
     }
     else
     {
         result = null;
         return(false);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Tries to perform binding of the dynamic get index operation.
        /// </summary>
        /// <param name="binder">An instance of the <see cref="GetIndexBinder"/> that represents the details of the dynamic operation.</param>
        /// <param name="instance">The target of the dynamic operation. </param>
        /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
        /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param>
        /// <returns>True if operation was bound successfully; otherwise, false.</returns>
        public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            Requires.NotNull(binder, nameof(binder));
            Requires.NotNull(instance, nameof(instance));
            Requires.NotNull(args, nameof(args));

            if (TryGetMetaObjectInvoke(ref instance))
            {
                result = instance.BindGetIndex(binder, args);
                return(true);
            }

            result = null;
            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Tries to perform binding of the dynamic get index operation.
        /// </summary>
        /// <param name="binder">An instance of the <see cref="GetIndexBinder"/> that represents the details of the dynamic operation.</param>
        /// <param name="instance">The target of the dynamic operation. </param>
        /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param>
        /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param>
        /// <returns>true if operation was bound successfully; otherwise, false.</returns>
        public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObjectInvoke(ref instance))
            {
                result = instance.BindGetIndex(binder, args);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
            public static void TestMetaObject(DynamicMetaObject target, int index, bool isValid = true)
            {
                string expectedMethodSignature = "System.Json.JsonValue GetValue(Int32)";

                GetIndexBinder binder = new TestGetIndexBinder();

                DynamicMetaObject[] indexes = { new DynamicMetaObject(Expression.Parameter(typeof(int)), BindingRestrictions.Empty, index) };

                DynamicMetaObject result = target.BindGetIndex(binder, indexes);

                Assert.IsNotNull(result);

                MethodCallExpression expression = result.Expression as MethodCallExpression;

                Assert.IsNotNull(expression);
                Assert.AreEqual <string>(expectedMethodSignature, expression.Method.ToString());
            }
Exemplo n.º 8
0
        public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)
        {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObject(ref instance))
            {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindGetIndex(binder, args);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 9
0
 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
 {
     return(AddRestrictions(_metaForwardee.BindGetIndex(binder, indexes)));
 }
        /// <summary>
        /// Performs the binding of the dynamic get index operation.
        /// </summary>
        /// <param name="target">The target of the dynamic get index operation.</param>
        /// <param name="args">An array of arguments of the dynamic get index operation.</param>
        /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
        public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
            ContractUtils.RequiresNotNull(target, "target");
            ContractUtils.RequiresNotNullItems(args, "args");

            return target.BindGetIndex(this, args);
        }
Exemplo n.º 11
0
 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
 {
     return(scriptItem.PostProcessBindResult(metaDynamic.BindGetIndex(binder, indexes)));
 }
Exemplo n.º 12
0
 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) => _innerMetaObject.BindGetIndex(binder, indexes);
Exemplo n.º 13
0
        public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");

            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindGetIndex(binder, args);
                return true;
            } else {
                result = null;
                return false;
            }
        }
Exemplo n.º 14
0
 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
 {
     return(binder.FallbackGetIndex(_baseMetaObject,
                                    indexes,
                                    AddTypeRestrictions(_metaObject.BindGetIndex(binder, indexes))));
 }
Exemplo n.º 15
0
 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
 {
     return(metaObject.BindGetIndex(binder, indexes));
 }