private static Expression[] GetArgArray(DynamicMetaObject[] args) { return(new NewArrayExpression[] { Expression.NewArrayInit(typeof(object), DynamicProxyMetaObject <T> .GetArgs(args)) }); }
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))); }
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))); }
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { if (!this.IsOverridden("TryInvoke")) { return(base.BindInvoke(binder, args)); } return(this.CallMethodWithResult("TryInvoke", binder, DynamicProxyMetaObject <T> .GetArgArray(args), (DynamicMetaObject e) => binder.FallbackInvoke(this, args, e), null)); }
public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) { if (!this.IsOverridden("TrySetIndex")) { return(base.BindSetIndex(binder, indexes, value)); } return(this.CallMethodReturnLast("TrySetIndex", binder, DynamicProxyMetaObject <T> .GetArgArray(indexes, value), (DynamicMetaObject e) => binder.FallbackSetIndex(this, indexes, value, e))); }
public override DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes) { if (!this.IsOverridden("TryDeleteIndex")) { return(base.BindDeleteIndex(binder, indexes)); } return(this.CallMethodNoResult("TryDeleteIndex", binder, DynamicProxyMetaObject <T> .GetArgArray(indexes), (DynamicMetaObject e) => binder.FallbackDeleteIndex(this, indexes, e))); }
public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) { if (!this.IsOverridden("TrySetMember")) { return(base.BindSetMember(binder, value)); } return(this.CallMethodReturnLast("TrySetMember", binder, DynamicProxyMetaObject <T> .GetArgs(new DynamicMetaObject[] { value }), (DynamicMetaObject e) => binder.FallbackSetMember(this, value, e))); }
public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) { if (!this.IsOverridden("TryGetIndex")) { return(base.BindGetIndex(binder, indexes)); } return(this.CallMethodWithResult("TryGetIndex", binder, DynamicProxyMetaObject <T> .GetArgArray(indexes), e => binder.FallbackGetIndex((DynamicProxyMetaObject <T>) this, indexes, e), null)); }
public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) { if (!this.IsOverridden("TryCreateInstance")) { return(base.BindCreateInstance(binder, args)); } return(this.CallMethodWithResult("TryCreateInstance", binder, DynamicProxyMetaObject <T> .GetArgArray(args), e => binder.FallbackCreateInstance((DynamicProxyMetaObject <T>) this, args, e), null)); }
private static Expression[] GetArgArray(DynamicMetaObject[] args, DynamicMetaObject value) { return(new Expression[] { Expression.NewArrayInit(typeof(object), DynamicProxyMetaObject <T> .GetArgs(args)), Expression.Convert(value.Expression, typeof(object)) }); }
public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) { if (!this.IsOverridden("TryBinaryOperation")) { return(base.BindBinaryOperation(binder, arg)); } return(this.CallMethodWithResult("TryBinaryOperation", binder, DynamicProxyMetaObject <T> .GetArgs(new DynamicMetaObject[] { arg }), (DynamicMetaObject e) => binder.FallbackBinaryOperation(this, arg, e), null)); }
public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { if (!this.IsOverridden("TryInvokeMember")) { return(base.BindInvokeMember(binder, args)); } DynamicProxyMetaObject <T> .Fallback fallback = (DynamicMetaObject e) => binder.FallbackInvokeMember(this, args, e); return(this.BuildCallMethodWithResult("TryInvokeMember", binder, DynamicProxyMetaObject <T> .GetArgArray(args), this.BuildCallMethodWithResult("TryGetMember", new DynamicProxyMetaObject <T> .GetBinderAdapter(binder), DynamicProxyMetaObject <T> .NoArgs, fallback(null), (DynamicMetaObject e) => binder.FallbackInvoke(e, args, null)), null)); }
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))); }
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, 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); }
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); }
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))); }
private DynamicMetaObject CallMethodWithResult(string methodName, DynamicMetaObjectBinder binder, Expression[] args, DynamicProxyMetaObject <T> .Fallback fallback, DynamicProxyMetaObject <T> .Fallback fallbackInvoke = null) { DynamicMetaObject fallbackResult = fallback(null); DynamicMetaObject dynamicMetaObject = this.BuildCallMethodWithResult(methodName, binder, args, fallbackResult, fallbackInvoke); if (!this._dontFallbackFirst) { return(fallback(dynamicMetaObject)); } return(dynamicMetaObject); }
private static System.Linq.Expressions.Expression[] GetArgArray(DynamicMetaObject[] args, DynamicMetaObject value) { System.Linq.Expressions.Expression expression; System.Linq.Expressions.Expression expression1 = value.Expression; System.Linq.Expressions.Expression[] expressionArray = new System.Linq.Expressions.Expression[] { System.Linq.Expressions.Expression.NewArrayInit(typeof(object), DynamicProxyMetaObject <T> .GetArgs(args)), null }; if (expression1.Type.IsValueType()) { expression = System.Linq.Expressions.Expression.Convert(expression1, typeof(object)); } else { expression = expression1; } expressionArray[1] = expression; return(expressionArray); }
private DynamicMetaObject CallMethodWithResult(string methodName, DynamicMetaObjectBinder binder, IEnumerable <System.Linq.Expressions.Expression> args, DynamicProxyMetaObject <T> .Fallback fallback, DynamicProxyMetaObject <T> .Fallback fallbackInvoke = null) { DynamicMetaObject dynamicMetaObject = fallback(null); return(this.BuildCallMethodWithResult(methodName, binder, args, dynamicMetaObject, fallbackInvoke)); }
public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { if (!this.IsOverridden("TryInvokeMember")) { return(base.BindInvokeMember(binder, args)); } Fallback <T> fallback = e => binder.FallbackInvokeMember((DynamicProxyMetaObject <T>) this, args, e); DynamicMetaObject errorSuggestion = this.BuildCallMethodWithResult("TryInvokeMember", binder, DynamicProxyMetaObject <T> .GetArgArray(args), this.BuildCallMethodWithResult("TryGetMember", new GetBinderAdapter <T>(binder), DynamicProxyMetaObject <T> .NoArgs, fallback(null), e => binder.FallbackInvoke(e, args, null)), null); if (!this._dontFallbackFirst) { return(fallback(errorSuggestion)); } return(errorSuggestion); }