Exemplo n.º 1
0
        private DynamicMetaObject BuildCallMethodWithResult(string methodName, DynamicMetaObjectBinder binder, IEnumerable <System.Linq.Expressions.Expression> args, DynamicMetaObject fallbackResult, DynamicProxyMetaObject <T> .Fallback fallbackInvoke)
        {
            ParameterExpression parameterExpression = System.Linq.Expressions.Expression.Parameter(typeof(object), null);
            IList <System.Linq.Expressions.Expression> expressions = new List <System.Linq.Expressions.Expression>()
            {
                System.Linq.Expressions.Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            expressions.AddRange <System.Linq.Expressions.Expression>(args);
            expressions.Add(parameterExpression);
            DynamicMetaObject dynamicMetaObject = new DynamicMetaObject(parameterExpression, BindingRestrictions.Empty);

            if (binder.ReturnType != typeof(object))
            {
                dynamicMetaObject = new DynamicMetaObject(System.Linq.Expressions.Expression.Convert(dynamicMetaObject.Expression, binder.ReturnType), dynamicMetaObject.Restrictions);
            }
            if (fallbackInvoke != null)
            {
                dynamicMetaObject = fallbackInvoke(dynamicMetaObject);
            }
            ParameterExpression[] parameterExpressionArray       = new ParameterExpression[] { parameterExpression };
            System.Linq.Expressions.Expression[] expressionArray = new System.Linq.Expressions.Expression[] { System.Linq.Expressions.Expression.Condition(System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), expressions), dynamicMetaObject.Expression, fallbackResult.Expression, binder.ReturnType) };
            return(new DynamicMetaObject(System.Linq.Expressions.Expression.Block((IEnumerable <ParameterExpression>)parameterExpressionArray, expressionArray), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions).Merge(fallbackResult.Restrictions)));
        }
Exemplo n.º 2
0
        private DynamicMetaObject BuildCallMethodWithResult(string methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicMetaObject fallbackResult, DynamicProxyMetaObject <T> .Fallback fallbackInvoke)
        {
            ParameterExpression parameterExpression = Expression.Parameter(typeof(object), null);
            IList <Expression>  list = new List <Expression>();

            list.Add(Expression.Convert(base.Expression, typeof(T)));
            list.Add(DynamicProxyMetaObject <T> .Constant(binder));
            list.AddRange(args);
            list.Add(parameterExpression);
            DynamicMetaObject dynamicMetaObject = new DynamicMetaObject(parameterExpression, BindingRestrictions.Empty);

            if (binder.ReturnType != typeof(object))
            {
                UnaryExpression expression = Expression.Convert(dynamicMetaObject.Expression, binder.ReturnType);
                dynamicMetaObject = new DynamicMetaObject(expression, dynamicMetaObject.Restrictions);
            }
            if (fallbackInvoke != null)
            {
                dynamicMetaObject = fallbackInvoke(dynamicMetaObject);
            }
            return(new DynamicMetaObject(Expression.Block(new ParameterExpression[]
            {
                parameterExpression
            }, new Expression[]
            {
                Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), list), dynamicMetaObject.Expression, fallbackResult.Expression, binder.ReturnType)
            }), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions).Merge(fallbackResult.Restrictions)));
        }
Exemplo n.º 3
0
        private DynamicMetaObject CallMethodNoResult(string methodName, DynamicMetaObjectBinder binder, System.Linq.Expressions.Expression[] args, DynamicProxyMetaObject <T> .Fallback fallback)
        {
            DynamicMetaObject dynamicMetaObject = fallback(null);
            IList <System.Linq.Expressions.Expression> expressions = new List <System.Linq.Expressions.Expression>()
            {
                System.Linq.Expressions.Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            expressions.AddRange <System.Linq.Expressions.Expression>(args);
            return(new DynamicMetaObject(System.Linq.Expressions.Expression.Condition(System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), expressions), System.Linq.Expressions.Expression.Empty(), dynamicMetaObject.Expression, typeof(void)), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions)));
        }
Exemplo n.º 4
0
        private DynamicMetaObject CallMethodNoResult(string methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicProxyMetaObject <T> .Fallback fallback)
        {
            DynamicMetaObject  dynamicMetaObject = fallback(null);
            IList <Expression> list = new List <Expression>();

            list.Add(Expression.Convert(base.Expression, typeof(T)));
            list.Add(DynamicProxyMetaObject <T> .Constant(binder));
            list.AddRange(args);
            DynamicMetaObject dynamicMetaObject2 = new DynamicMetaObject(Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), list), Expression.Empty(), dynamicMetaObject.Expression, typeof(void)), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions));

            if (!this._dontFallbackFirst)
            {
                return(fallback(dynamicMetaObject2));
            }
            return(dynamicMetaObject2);
        }
Exemplo n.º 5
0
        private DynamicMetaObject CallMethodReturnLast(string methodName, DynamicMetaObjectBinder binder, IEnumerable <System.Linq.Expressions.Expression> args, DynamicProxyMetaObject <T> .Fallback fallback)
        {
            DynamicMetaObject   dynamicMetaObject   = fallback(null);
            ParameterExpression parameterExpression = System.Linq.Expressions.Expression.Parameter(typeof(object), null);
            IList <System.Linq.Expressions.Expression> expressions = new List <System.Linq.Expressions.Expression>()
            {
                System.Linq.Expressions.Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            expressions.AddRange <System.Linq.Expressions.Expression>(args);
            expressions[expressions.Count - 1] = System.Linq.Expressions.Expression.Assign(parameterExpression, expressions[expressions.Count - 1]);
            ParameterExpression[] parameterExpressionArray       = new ParameterExpression[] { parameterExpression };
            System.Linq.Expressions.Expression[] expressionArray = new System.Linq.Expressions.Expression[] { System.Linq.Expressions.Expression.Condition(System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), expressions), parameterExpression, dynamicMetaObject.Expression, typeof(object)) };
            return(new DynamicMetaObject(System.Linq.Expressions.Expression.Block((IEnumerable <ParameterExpression>)parameterExpressionArray, expressionArray), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions)));
        }
        private DynamicMetaObject CallMethodNoResult(string methodName, DynamicMetaObjectBinder binder, Expression[] args, Fallback <T> fallback)
        {
            DynamicMetaObject  obj2    = fallback(null);
            IList <Expression> initial = new List <Expression> {
                Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            initial.AddRange <Expression>(args);
            DynamicMetaObject errorSuggestion = new DynamicMetaObject(Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), initial), Expression.Empty(), obj2.Expression, typeof(void)), this.GetRestrictions().Merge(obj2.Restrictions));

            if (!this._dontFallbackFirst)
            {
                return(fallback(errorSuggestion));
            }
            return(errorSuggestion);
        }
        private DynamicMetaObject CallMethodReturnLast(string methodName, DynamicMetaObjectBinder binder, Expression[] args, Fallback <T> fallback)
        {
            DynamicMetaObject   obj2    = fallback(null);
            ParameterExpression left    = Expression.Parameter(typeof(object), null);
            IList <Expression>  initial = new List <Expression> {
                Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            initial.AddRange <Expression>(args);
            initial[args.Length + 1] = Expression.Assign(left, initial[args.Length + 1]);
            ParameterExpression[] variables       = new ParameterExpression[] { left };
            Expression[]          expressions     = new Expression[] { Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), initial), left, obj2.Expression, typeof(object)) };
            DynamicMetaObject     errorSuggestion = new DynamicMetaObject(Expression.Block(variables, expressions), this.GetRestrictions().Merge(obj2.Restrictions));

            if (!this._dontFallbackFirst)
            {
                return(fallback(errorSuggestion));
            }
            return(errorSuggestion);
        }
Exemplo n.º 8
0
        private DynamicMetaObject CallMethodReturnLast(string methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicProxyMetaObject <T> .Fallback fallback)
        {
            DynamicMetaObject   dynamicMetaObject   = fallback(null);
            ParameterExpression parameterExpression = Expression.Parameter(typeof(object), null);
            IList <Expression>  list = new List <Expression>();

            list.Add(Expression.Convert(base.Expression, typeof(T)));
            list.Add(DynamicProxyMetaObject <T> .Constant(binder));
            list.AddRange(args);
            list[args.Length + 1] = Expression.Assign(parameterExpression, list[args.Length + 1]);
            DynamicMetaObject dynamicMetaObject2 = new DynamicMetaObject(Expression.Block(new ParameterExpression[]
            {
                parameterExpression
            }, new Expression[]
            {
                Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), list), parameterExpression, dynamicMetaObject.Expression, typeof(object))
            }), this.GetRestrictions().Merge(dynamicMetaObject.Restrictions));

            if (!this._dontFallbackFirst)
            {
                return(fallback(dynamicMetaObject2));
            }
            return(dynamicMetaObject2);
        }
        private DynamicMetaObject BuildCallMethodWithResult(string methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicMetaObject fallbackResult, Fallback <T> fallbackInvoke)
        {
            ParameterExpression item    = Expression.Parameter(typeof(object), null);
            IList <Expression>  initial = new List <Expression> {
                Expression.Convert(base.Expression, typeof(T)),
                DynamicProxyMetaObject <T> .Constant(binder)
            };

            initial.AddRange <Expression>(args);
            initial.Add(item);
            DynamicMetaObject errorSuggestion = new DynamicMetaObject(item, BindingRestrictions.Empty);

            if (binder.ReturnType != typeof(object))
            {
                errorSuggestion = new DynamicMetaObject(Expression.Convert(errorSuggestion.Expression, binder.ReturnType), errorSuggestion.Restrictions);
            }
            if (fallbackInvoke != null)
            {
                errorSuggestion = fallbackInvoke(errorSuggestion);
            }
            ParameterExpression[] variables   = new ParameterExpression[] { item };
            Expression[]          expressions = new Expression[] { Expression.Condition(Expression.Call(Expression.Constant(this._proxy), typeof(DynamicProxy <T>).GetMethod(methodName), initial), errorSuggestion.Expression, fallbackResult.Expression, binder.ReturnType) };
            return(new DynamicMetaObject(Expression.Block(variables, expressions), this.GetRestrictions().Merge(errorSuggestion.Restrictions).Merge(fallbackResult.Restrictions)));
        }