Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with async methods in generic class fixed. #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rumyash
Copy link

@Rumyash Rumyash commented Dec 31, 2018

There are two problems with interseption async methods in generic classes.
The first - the missed generic argument in the state machine's field, the second - the empty names of fields and parameters.
Source code:

public class SimpleMethodInterceptorTest<T>
{
    [TestMethodInterceptor]
    public async Task<T> AsyncMethodWithParameters(int a, string b)
    {
        return await Task.Run(() => default(T));
    }
}

Generated code:

...
[AsyncStateMachine(typeof (SimpleMethodInterceptorTest<>.\u003CAsyncMethodWithParameters\u003Ed__0))]
[DebuggerStepThrough]
public Task<T> AsyncMethodWithParameters(int a, string b)
{
  if (this.\u003CAsyncMethodWithParameters\u003E_fwelbpjc2mc1 == null)
    this.\u003CAsyncMethodWithParameters\u003E_fwelbpjc2mc1 = (IMethodInterceptor) new TestMethodInterceptorAttribute();
  SimpleMethodInterceptorTest<T>.\u003CAsyncMethodWithParameters\u003Ed__0 stateMachine = new SimpleMethodInterceptorTest<T>.\u003CAsyncMethodWithParameters\u003Ed__0();
  stateMachine.\u003C\u003E4__this = this;
  stateMachine.a = a;
  stateMachine.b = b;
  stateMachine.\u003C\u003Et__builder = AsyncTaskMethodBuilder<T>.Create();
  stateMachine.\u003C\u003E1__state = -1;
  ((SimpleMethodInterceptorTest<>.\u003CAsyncMethodWithParameters\u003Ed__0) stateMachine). = a;
  ((SimpleMethodInterceptorTest<>.\u003CAsyncMethodWithParameters\u003Ed__0) stateMachine).\u003CAsyncMethodWithParameters\u003E_fwelbpjc2mc1 = this.\u003CAsyncMethodWithParameters\u003E_fwelbpjc2mc1; // the first problem
  stateMachine.\u003C\u003Et__builder.Start<SimpleMethodInterceptorTest<T>.\u003CAsyncMethodWithParameters\u003Ed__0>(ref stateMachine);
  return stateMachine.\u003C\u003Et__builder.Task;
}
...
[CompilerGenerated]
private sealed class \u003CAsyncMethodWithParameters\u003Ed__0 : IAsyncStateMachine
{
  public int \u003C\u003E1__state;
  public AsyncTaskMethodBuilder<T> \u003C\u003Et__builder;
  public int a;
  public string b;
  public SimpleMethodInterceptorTest<T> \u003C\u003E4__this;
  private T \u003C\u003Es__1;
  private TaskAwaiter<T> \u003C\u003Eu__1;
  public IMethodInterceptor \u003CAsyncMethodWithParameters\u003E_fwelbpjc2mc1;
  public int ; // the second problem

  public \u003CAsyncMethodWithParameters\u003Ed__0()
  {
    base.\u002Ector();
  }

  void IAsyncStateMachine.MoveNext()
  {
    int num1 = this.\u003C\u003E1__state;
    T s1;
    try
    {
      object[] values = new object[2]
      {
        (object) this.,
        (object) this.
      }; // the second problem
...

@Rumyash Rumyash force-pushed the intercept_async_method_in_generic_class branch from 134565f to 80ba0ab Compare January 1, 2019 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant