示例#1
0
        /// <summary>
        /// Performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
        /// </summary>
        /// <param name="target">The target of the dynamic set index operation.</param>
        /// <param name="indexes">The arguments of the dynamic set index operation.</param>
        /// <param name="value">The value to set to the collection.</param>
        /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
        /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
        public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
#if ENABLECOMBINDER
            DynamicMetaObject com;
            if (!BinderHelper.IsWindowsRuntimeObject(target) && ComBinder.TryBindSetIndex(this, target, indexes, value, out com))
            {
                return(com);
            }
#endif
            return(BinderHelper.Bind(this, _binder, BinderHelper.Cons(target, indexes, value), _argumentInfo, errorSuggestion));
        }
示例#2
0
        public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject?errorSuggestion)
        {
            // First try COM binding.
            if (ComBinder.TryBindSetIndex(this, target, indexes, value, out var result))
            {
                return(result);
            }

            // Defer if any object has no value so that we evaulate their Expressions and nest a
            // CallSite for the InvokeMember.
            if (!target.HasValue || !value.HasValue || Array.Exists(indexes, a => !a.HasValue))
            {
                var deferArgs = new DynamicMetaObject[indexes.Length + 2];
                indexes.CopyTo(deferArgs.AsSpan(1));
                deferArgs[0]   = target;
                deferArgs[^ 1] = value;
示例#3
0
        public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
            if (ComBinder.TryBindSetIndex(this, target, indexes, value, out DynamicMetaObject result))
            {
                return(result);
            }

            if (!target.HasValue || !value.HasValue || indexes.Any(x => !x.HasValue))
            {
                return(Defer(target, indexes));
            }

            var arrayAccess = RuntimeHelpers.GetIndexingExpression(target, indexes);
            var setIndex    = Expression.Assign(arrayAccess, Expression.Convert(value.Expression, value.LimitType));

            var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(target, indexes, false);

            return(new DynamicMetaObject(RuntimeHelpers.EnsureObjectResult(setIndex), restrictions));
        }