NET35 doesn't seem to support Expression.Variable.

Added back previous DelegateProxyFactory implementation from
ac140ef7ba for NET35 target only.

Updated test accordingingly.
This commit is contained in:
David Tchepak 2017-01-04 10:06:50 +11:00
Родитель 1e9e8a31d7
Коммит 6f82b2f2a4
2 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -15,7 +15,11 @@ namespace NSubstitute.Acceptance.Specs.FieldReports
foo(out bar);
#if NET4 || NET45
Assert.AreEqual(42, bar);
#else
Assert.Ignore("Not supported for NET35");
#endif
}
}
}

Просмотреть файл

@ -41,6 +41,28 @@ namespace NSubstitute.Proxies.DelegateProxy
ParameterExpression[] proxyParameters = delegateMethodToProxy.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
Expression[] proxyParametersAsObjects = proxyParameters.Select(x => (Expression)Expression.Convert(x, typeof(object))).ToArray();
#if NET35
Expression callInvokeOnDelegateCallInstance =
Expression.Call(
Expression.Constant(delegateCall),
invokeOnDelegateCall,
new Expression[]
{
Expression.NewArrayInit(typeof(object), proxyParametersAsObjects)
}
);
if (delegateMethodToProxy.ReturnType != typeof(void))
{
callInvokeOnDelegateCallInstance =
Expression.Convert(callInvokeOnDelegateCallInstance, delegateMethodToProxy.ReturnType);
}
var proxyExpression = Expression.Lambda(delegateType, callInvokeOnDelegateCallInstance, proxyParameters);
return proxyExpression.Compile();
#endif
#if !NET35
var bodyExpressions = new List<Expression>();
bool isVoid = delegateMethodToProxy.ReturnType == typeof(void);
var arguments = Expression.Variable(typeof(object[]), "arguments");
@ -71,6 +93,7 @@ namespace NSubstitute.Proxies.DelegateProxy
var variables = isVoid ? new[] { arguments } : new[] { arguments, result };
var proxyExpression = Expression.Lambda(delegateType, Expression.Block(variables, bodyExpressions), proxyParameters);
return proxyExpression.Compile();
#endif
}
}
}