GetExpressions() static private method

Returns the list of expressions represented by the DynamicMetaObject instances.
static private GetExpressions ( DynamicMetaObject objects ) : System.Linq.Expressions.Expression[]
objects DynamicMetaObject An array of instances to extract expressions from.
return System.Linq.Expressions.Expression[]
        private DynamicMetaObject MakeDeferred(BindingRestrictions rs, params DynamicMetaObject[] args)
        {
            Expression[] expressions  = DynamicMetaObject.GetExpressions(args);
            Type         delegateType = DelegateHelpers.MakeDeferredSiteDelegate(args, this.ReturnType);

            return(new DynamicMetaObject(DynamicExpression.Make(this.ReturnType, delegateType, this, new TrueReadOnlyCollection <Expression>(expressions)), rs));
        }
Beispiel #2
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                // Generate a tree like:
                //
                // {
                //   object result;
                //   TryInvokeMember(payload, out result)
                //      ? result
                //      : TryGetMember(payload, out result)
                //          ? FallbackInvoke(result)
                //          : fallbackResult
                // }
                //
                // Then it calls FallbackInvokeMember with this tree as the
                // "error", giving the language the option of using this
                // tree or doing .NET binding.
                //
                Fallback fallback = e => binder.FallbackInvokeMember(this, args, e);

                var call = BuildCallMethodWithResult(
                    "TryInvokeMember",
                    binder,
                    DynamicMetaObject.GetExpressions(args),
                    BuildCallMethodWithResult <GetMemberBinder>(
                        "TryGetMember",
                        new GetBinderAdapter(binder),
                        s_noArgs,
                        fallback(null),
                        (e) => binder.FallbackInvoke(e, args, null)
                        ),
                    null
                    );

                return(fallback(call));
            }
Beispiel #3
0
            public override DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes)
            {
                if (IsOverridden("TryDeleteIndex"))
                {
                    return(CallMethodNoResult("TryDeleteIndex", binder, DynamicMetaObject.GetExpressions(indexes), (e) => binder.FallbackDeleteIndex(this, indexes, e)));
                }

                return(base.BindDeleteIndex(binder, indexes));
            }
Beispiel #4
0
            public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
            {
                if (IsOverridden("TrySetIndex"))
                {
                    return(CallMethodReturnLast("TrySetIndex", binder, DynamicMetaObject.GetExpressions(indexes), value.Expression, (e) => binder.FallbackSetIndex(this, indexes, value, e)));
                }

                return(base.BindSetIndex(binder, indexes, value));
            }
Beispiel #5
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));
            }
Beispiel #6
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
            {
                if (IsOverridden("TryInvoke"))
                {
                    return(CallMethodWithResult("TryInvoke", binder, DynamicMetaObject.GetExpressions(args), (e) => binder.FallbackInvoke(this, args, e)));
                }

                return(base.BindInvoke(binder, args));
            }
Beispiel #7
0
 private static Expression[] GetArgs(params DynamicMetaObject[] args)
 {
     Expression[] expressions = DynamicMetaObject.GetExpressions(args);
     for (int i = 0; i < expressions.Length; i++)
     {
         expressions[i] = Expression.Convert(args[i].Expression, typeof(object));
     }
     return(expressions);
 }
Beispiel #8
0
        private DynamicMetaObject MakeDeferred(BindingRestrictions rs, params DynamicMetaObject[] args)
        {
            var exprs = DynamicMetaObject.GetExpressions(args);

            Type delegateType = DelegateHelpers.MakeDeferredSiteDelegate(args, ReturnType);

            // Because we know the arguments match the delegate type (we just created the argument types)
            // we go directly to DynamicExpression.Make to avoid a bunch of unnecessary argument validation
            return(new DynamicMetaObject(
                       DynamicExpression.Make(ReturnType, delegateType, this, new TrueReadOnlyCollection <Expression>(exprs)),
                       rs
                       ));
        }
Beispiel #9
0
        private DynamicMetaObject MakeDeferred(BindingRestrictions rs, params DynamicMetaObject[] args)
        {
            var expressions = DynamicMetaObject.GetExpressions(args);

            var delegateType = DelegateHelper.GetDelegateTypeInternal(args.ConvertAll(ToType).Prepend(typeof(CallSite)).Append(ReturnType).ToArray());

            // Because we know the arguments match the delegate type (we just created the argument types)
            // we go directly to DynamicExpression.Make to avoid a bunch of unnecessary argument validation
            return(new DynamicMetaObject
                   (
                       DynamicExpression.Make(ReturnType, delegateType, this, expressions),
                       rs
                   ));
Beispiel #10
0
            public override DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes)
            {
                if (IsOverridden(nameof(DynamicObject.TryDeleteIndex)))
                {
                    DynamicMetaObject[] localIndexes = indexes;

                    return(CallMethodNoResult(
                               nameof(DynamicObject.TryDeleteIndex),
                               binder,
                               DynamicMetaObject.GetExpressions(indexes),
                               (MetaDynamic @this, DeleteIndexBinder b, DynamicMetaObject e) => b.FallbackDeleteIndex(@this, localIndexes, e)
                               ));
                }

                return(base.BindDeleteIndex(binder, indexes));
            }
Beispiel #11
0
            public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
            {
                if (IsOverridden(nameof(DynamicObject.TryBinaryOperation)))
                {
                    DynamicMetaObject localArg = arg;

                    return(CallMethodWithResult(
                               nameof(DynamicObject.TryBinaryOperation),
                               binder,
                               DynamicMetaObject.GetExpressions(new DynamicMetaObject[] { arg }),
                               (MetaDynamic @this, BinaryOperationBinder b, DynamicMetaObject e) => b.FallbackBinaryOperation(@this, localArg, e)
                               ));
                }

                return(base.BindBinaryOperation(binder, arg));
            }
Beispiel #12
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
            {
                if (IsOverridden(nameof(DynamicObject.TryInvoke)))
                {
                    DynamicMetaObject[] localArgs = args;

                    return(CallMethodWithResult(
                               nameof(DynamicObject.TryInvoke),
                               binder,
                               DynamicMetaObject.GetExpressions(args),
                               (MetaDynamic @this, InvokeBinder b, DynamicMetaObject e) => b.FallbackInvoke(@this, localArgs, e)
                               ));
                }

                return(base.BindInvoke(binder, args));
            }
Beispiel #13
0
            public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
            {
                if (IsOverridden(nameof(DynamicObject.TrySetIndex)))
                {
                    DynamicMetaObject[] localIndexes = indexes;
                    DynamicMetaObject   localValue   = value;

                    return(CallMethodReturnLast(
                               nameof(DynamicObject.TrySetIndex),
                               binder,
                               DynamicMetaObject.GetExpressions(indexes),
                               value.Expression,
                               (MetaDynamic @this, SetIndexBinder b, DynamicMetaObject e) => b.FallbackSetIndex(@this, localIndexes, localValue, e)
                               ));
                }

                return(base.BindSetIndex(binder, indexes, value));
            }
Beispiel #14
0
            public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
            {
                if (IsOverridden(nameof(DynamicObject.TryGetIndex)))
                {
                    return(CallMethodWithResult(nameof(DynamicObject.TryGetIndex), binder, DynamicMetaObject.GetExpressions(indexes), (e) => binder.FallbackGetIndex(this, indexes, e)));
                }

                return(base.BindGetIndex(binder, indexes));
            }
Beispiel #15
0
            public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
            {
                if (IsOverridden(nameof(DynamicObject.TryCreateInstance)))
                {
                    return(CallMethodWithResult(nameof(DynamicObject.TryCreateInstance), binder, DynamicMetaObject.GetExpressions(args), (e) => binder.FallbackCreateInstance(this, args, e)));
                }

                return(base.BindCreateInstance(binder, args));
            }