Browse Source

Remove reflection for ExecuteWithoutReturnValueAsync

pull/2464/head
Halil İbrahim Kalkan 7 years ago
parent
commit
c4b2d2b48c
  1. 21
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs

21
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs

@ -9,13 +9,6 @@ namespace Volo.Abp.Castle.DynamicProxy
public class CastleAbpInterceptorAdapter<TInterceptor> : IInterceptor public class CastleAbpInterceptorAdapter<TInterceptor> : IInterceptor
where TInterceptor : IAbpInterceptor where TInterceptor : IAbpInterceptor
{ {
private static readonly MethodInfo MethodExecuteWithoutReturnValueAsync =
typeof(CastleAbpInterceptorAdapter<TInterceptor>)
.GetMethod(
nameof(ExecuteWithoutReturnValueAsync),
BindingFlags.NonPublic | BindingFlags.Instance
);
private static readonly MethodInfo MethodExecuteWithReturnValueAsync = private static readonly MethodInfo MethodExecuteWithReturnValueAsync =
typeof(CastleAbpInterceptorAdapter<TInterceptor>) typeof(CastleAbpInterceptorAdapter<TInterceptor>)
.GetMethod( .GetMethod(
@ -36,22 +29,20 @@ namespace Volo.Abp.Castle.DynamicProxy
var method = invocation.MethodInvocationTarget ?? invocation.Method; var method = invocation.MethodInvocationTarget ?? invocation.Method;
if (method.IsAsync()) if (!method.IsAsync())
{
InterceptAsyncMethod(invocation, proceedInfo);
}
else
{ {
proceedInfo.Invoke(); proceedInfo.Invoke();
return;
} }
InterceptAsyncMethod(invocation, proceedInfo);
} }
private void InterceptAsyncMethod(IInvocation invocation, IInvocationProceedInfo proceedInfo) private void InterceptAsyncMethod(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{ {
if (invocation.Method.ReturnType == typeof(Task)) if (invocation.Method.ReturnType == typeof(Task))
{ {
invocation.ReturnValue = MethodExecuteWithoutReturnValueAsync invocation.ReturnValue = ExecuteWithoutReturnValueAsync(invocation, proceedInfo);
.Invoke(this, new object[] { invocation, proceedInfo });
} }
else else
{ {
@ -63,8 +54,6 @@ namespace Volo.Abp.Castle.DynamicProxy
private async Task ExecuteWithoutReturnValueAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo) private async Task ExecuteWithoutReturnValueAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{ {
await Task.Yield();
await _abpInterceptor.InterceptAsync( await _abpInterceptor.InterceptAsync(
new CastleAbpMethodInvocationAdapter(invocation, proceedInfo) new CastleAbpMethodInvocationAdapter(invocation, proceedInfo)
); );

Loading…
Cancel
Save