pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

About UniversalWrapper #158

Closed jerviscui closed 2 years ago

jerviscui commented 3 years ago

The UniversalWrapper.cs, if used for a sync method and return Task:

public Task ATask()
{
    return Task;
}

Will thorw a convert exception in (Task<T>)target(args). _asyncHandler need to add a check conditions methodInfo.GetCustomAttributes<AsyncStateMachineAttribute>().Any() conditions.

And UniversalWrapper use MethodBase.Invoke() method, I think Invoke() function doesn't have good performance.

How about add a async Around method for async method?

[Advice(Kind.Around, Targets = Target.Method)]
public void Handle()
{}

[Advice(Kind.Around, Targets = Target.Method)]
public async Task Handle()
{}

I don't know if I am right. Just a thought.

pamidur commented 3 years ago

Hi @jerviscui , we're currently working on more sophisticated version of Universal Wrapper here #148.

Apart of that I was long thinking about what you're suggesting - to make aspect compiler recognize and process async methods in different way. It would require some significant changes, so until then I guess upcoming version of #148 will do the trick

pamidur commented 2 years ago

I guess this should cover it https://github.com/pamidur/aspect-injector/pull/148 Feel free to reopen if needed