C#异步状态机反编译
我有几乎可以工作的代码,但是C#异步状态机反编译,c#,async-await,C#,Async Await,我有几乎可以工作的代码,但是OnRequest方法充满了错误,我认为它是编译后的代码。有什么帮助可以将此代码转换为人类可读的代码吗 [AsyncStateMachine(typeof(Service1.<OnRequest>d__24))] public Task OnRequest(object sender, SessionEventArgs e) { Service1.<OnRequest>d__24 <OnRequest>d__; &l
OnRequest
方法充满了错误,我认为它是编译后的代码。有什么帮助可以将此代码转换为人类可读的代码吗
[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;
}
[AsyncStateMachine(typeof(Service1.d_u24))]
公共任务OnRequest(对象发送方、SessionEventArgs e)
{
服务1.d_uu24 d_uu;
d_uuu.4_uuuthis=这个;
d___.e=e;
d_u.t_u builder=AsyncTaskMethodBuilder.Create();
d_uuu.1_uuu状态=-1;
AsyncTaskMethodBuilder t\uuuuu builder=d\uuuuu.t\uuuu builder;
建造商启动(参考d);
返回d_u.t_u builder.Task;
}
或者我在这里很无助,我不知道这是什么,我想在最坏的情况下解释,如果我不能解决这个问题 字符
对于类型和变量名无效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;
}
您的泛型位于变量名之后;请尝试d.IL Spy反编译
async
/wait
@Ares它们不是泛型-它们是(严重)反编译自动生成的标识符,反编译器无法正确理解。@Ares您实际想做什么?我有同样的提取问题,但在生成时,我在CS0165使用未赋值局部变量OnRequestd__________;时遇到了一个错误。请帮助。@Vietnguen09我已经有一段时间没有研究状态机的内部结构了,但在这种情况下,OnRequestd________;可能是因为它被定义为一个类,所以出现了错误。上面的代码使用一个OnRequestd\uu 24
结构进行编译。
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();
}
}