2017-07-20 558 views
3

我几乎有工作代码,但OnRequest方法是充满错误,我看到它是编译代码,我认为。任何帮助将此代码编入人类可读代码?C#AsyncStateMachine反编译

[AsyncStateMachine(typeof(Service1.<OnRequest>d__24))] 
     public Task OnRequest(object sender, SessionEventArgs e) 
     { 
      Service1.<OnRequest>d__24 <OnRequest>d__; 
      <OnRequest>d__.<>4__this = this; 
      <OnRequest>d__.e = e; 
      <OnRequest>d__.<>t__builder = AsyncTaskMethodBuilder.Create(); 
      <OnRequest>d__.<>1__state = -1; 
      AsyncTaskMethodBuilder <>t__builder = <OnRequest>d__.<>t__builder; 
      <>t__builder.Start<Service1.<OnRequest>d__24>(ref <OnRequest>d__); 
      return <OnRequest>d__.<>t__builder.Task; 
     } 

或者我在这里很无奈,我不知道那是什么,我想在最坏的情况下解释,如果我不能解决这个问题。

+0

您的泛型出现在变量名后面;尝试d 。 – Ares

+0

IL Spy [should support](http://community.sharpdevelop.net/blogs/danielgrunwald/archive/2012/04/16/decompiling-async-await.aspx)反编译'async' /'await'。 – GSerg

+2

@Ares它们不是泛型 - 它们(非常)反编译自动生成的标识符,反编译器不能正确理解。 –

回答

2

字符<>对于类型和变量名称无效C#,但它们在CIL代码中完全有效。

ILSpy没有“正常化”的名字,所以你得到的代码不编译,但你可以仅仅删除特殊字符来解决它:

[AsyncStateMachine(typeof(Service1.OnRequestd__24))] 
public Task OnRequest(object sender, SessionEventArgs e) 
{ 
    Service1.OnRequestd__24 OnRequestd__; 
    OnRequestd__.__this = this; 
    OnRequestd__.e = e; 
    OnRequestd__.t__builder = AsyncTaskMethodBuilder.Create(); 
    OnRequestd__.__state = -1; 
    AsyncTaskMethodBuilder t__builder = OnRequestd__.t__builder; 
    t__builder.Start<Service1.OnRequestd__24>(ref OnRequestd__); 
    return OnRequestd__.t__builder.Task; 
} 

这完全编译如果您还实现参考类型:

public class Service1 
{ 
    public struct OnRequestd__24 : IAsyncStateMachine 
    { 
     public ObjectPoolAutoTest __this; 
     public SessionEventArgs e; 
     public AsyncTaskMethodBuilder t__builder; 
     public int __state; 
     public void MoveNext() => throw new NotImplementedException(); 

     public void SetStateMachine(IAsyncStateMachine stateMachine) => throw new NotImplementedException(); 
    } 
}