简体   繁体   中英

C# AsyncStateMachine Decompile

I have nearly working code but OnRequest method is full of errors, I see that it's compiled code I think. Any help to make this code into human readable code?

[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;
}

Or I'm helpless here, I don't know what is that and I would like explanation in worst case if I can't have solution for this.

The characters < and > are not valid C# for type and variable names, but they are perfectly valid in CIL code.

ILSpy doesn't "normalize" names so you get code that is not compilable, but you can just remove the special characters to fix it:

[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;
}

This compiles perfectly if you also implement the referencing types:

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM