mirror of https://github.com/abpframework/abp.git
16 changed files with 183 additions and 186 deletions
@ -1,21 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Castle.DynamicProxy; |
|||
using Volo.Abp.DynamicProxy; |
|||
|
|||
namespace Volo.Abp.Castle.DynamicProxy |
|||
{ |
|||
public class CastleAbpAsyncMethodInvocationAdapter : CastleAbpMethodInvocationAdapterBase, IAbpAsyncMethodInvocation |
|||
{ |
|||
public CastleAbpAsyncMethodInvocationAdapter(IInvocation invocation) |
|||
: base(invocation) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public Task ProceedAsync() |
|||
{ |
|||
Invocation.Proceed(); |
|||
return (Task)Invocation.ReturnValue; |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +1,62 @@ |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
using System.Reflection; |
|||
using System.Threading.Tasks; |
|||
using Castle.DynamicProxy; |
|||
using Volo.Abp.DynamicProxy; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.Castle.DynamicProxy |
|||
{ |
|||
public class CastleAbpMethodInvocationAdapter : CastleAbpMethodInvocationAdapterBase, IAbpMethodInvocation |
|||
public class CastleAbpMethodInvocationAdapter : IAbpMethodInvocation |
|||
{ |
|||
public object[] Arguments => Invocation.Arguments; |
|||
|
|||
public Type[] GenericArguments => Invocation.GenericArguments; |
|||
|
|||
public object TargetObject => Invocation.InvocationTarget; |
|||
|
|||
public MethodInfo Method => Invocation.MethodInvocationTarget; |
|||
|
|||
public object ReturnValue |
|||
{ |
|||
get => Invocation.ReturnValue; |
|||
set => Invocation.ReturnValue = value; |
|||
} |
|||
|
|||
protected IInvocation Invocation { get; } |
|||
|
|||
public CastleAbpMethodInvocationAdapter(IInvocation invocation) |
|||
: base(invocation) |
|||
{ |
|||
Invocation = invocation; |
|||
} |
|||
|
|||
public Task ProceedAsync() |
|||
{ |
|||
return Invocation.Method.IsAsync() |
|||
? RunAsync() |
|||
: RunSync(); |
|||
} |
|||
|
|||
public void Proceed() |
|||
private Task RunAsync() |
|||
{ |
|||
if (Invocation.Method.IsAsync()) |
|||
Invocation.Proceed(); |
|||
return (Task) Invocation.ReturnValue; |
|||
} |
|||
|
|||
private Task RunSync() |
|||
{ |
|||
Invocation.Proceed(); |
|||
|
|||
if (Method.ReturnType == typeof(void)) |
|||
{ |
|||
Invocation.Proceed(); |
|||
AsyncHelper.RunSync(() => (Task) Invocation.ReturnValue); |
|||
return Task.CompletedTask; |
|||
} |
|||
else |
|||
{ |
|||
Invocation.Proceed(); |
|||
return (Task) typeof(Task) |
|||
.GetMethod("FromResult", BindingFlags.Static | BindingFlags.Public) |
|||
.MakeGenericMethod(Method.ReturnType) |
|||
.Invoke(null, new object[] {Invocation.ReturnValue}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,31 +0,0 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using Castle.DynamicProxy; |
|||
using Volo.Abp.DynamicProxy; |
|||
|
|||
namespace Volo.Abp.Castle.DynamicProxy |
|||
{ |
|||
public abstract class CastleAbpMethodInvocationAdapterBase : IAbpMethodInvocationCore |
|||
{ |
|||
public object[] Arguments => Invocation.Arguments; |
|||
|
|||
public Type[] GenericArguments => Invocation.GenericArguments; |
|||
|
|||
public object TargetObject => Invocation.InvocationTarget; |
|||
|
|||
public MethodInfo Method => Invocation.MethodInvocationTarget; |
|||
|
|||
public object ReturnValue |
|||
{ |
|||
get => Invocation.ReturnValue; |
|||
set => Invocation.ReturnValue = value; |
|||
} |
|||
|
|||
protected IInvocation Invocation { get; } |
|||
|
|||
protected CastleAbpMethodInvocationAdapterBase(IInvocation invocation) |
|||
{ |
|||
Invocation = invocation; |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.DynamicProxy |
|||
{ |
|||
public interface IAbpAsyncInterceptor |
|||
{ |
|||
Task InterceptAsync(IAbpAsyncMethodInvocation invocation); |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.DynamicProxy |
|||
{ |
|||
public interface IAbpAsyncMethodInvocation: IAbpMethodInvocationCore |
|||
{ |
|||
Task ProceedAsync(); |
|||
} |
|||
} |
|||
@ -1,7 +1,9 @@ |
|||
namespace Volo.Abp.DynamicProxy |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.DynamicProxy |
|||
{ |
|||
public interface IAbpInterceptor |
|||
{ |
|||
void Intercept(IAbpMethodInvocation invocation); |
|||
Task InterceptAsync(IAbpMethodInvocation invocation); |
|||
} |
|||
} |
|||
|
|||
@ -1,7 +1,21 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.DynamicProxy |
|||
{ |
|||
public interface IAbpMethodInvocation: IAbpMethodInvocationCore |
|||
public interface IAbpMethodInvocation |
|||
{ |
|||
void Proceed(); |
|||
object[] Arguments { get; } |
|||
|
|||
Type[] GenericArguments { get; } |
|||
|
|||
object TargetObject { get; } |
|||
|
|||
MethodInfo Method { get; } |
|||
|
|||
object ReturnValue { get; set; } |
|||
|
|||
Task ProceedAsync(); |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
|
|||
namespace Volo.Abp.DynamicProxy |
|||
{ |
|||
public interface IAbpMethodInvocationCore |
|||
{ |
|||
object[] Arguments { get; } |
|||
|
|||
Type[] GenericArguments { get; } |
|||
|
|||
object TargetObject { get; } |
|||
|
|||
MethodInfo Method { get; } |
|||
|
|||
object ReturnValue { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue