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

Add support for async main method #1029

Merged
merged 3 commits into from
Jan 19, 2018

Conversation

MikeFH
Copy link
Contributor

@MikeFH MikeFH commented Jan 15, 2018

Adds the feature described in #1023

I had a bit of a hard time writing the test since, until now, all tests generated DLLs and we need to generate an EXE to test that the entry point is decompiled correctly. I created a second method called RunForLibrary() to replace the old one and set the necessary flags to generate DLLs. This way we can use the Run() method to create an EXE file.

At this point, I don't see any other way to identify the generated method but by its name (see Roslyn). I put the logic to identify the method in the AsyncAwaitDecompiler since more checks could be added in the future to distinguish it.

@siegfriedpammer
Copy link
Member

Thank you for the contribution!
Please make sure to use tabs instead of spaces in new files. Thanks!
(If you have python installed, you can use https://gist.github.com/siegfriedpammer/75700ea61609eb22714d21885e4eb084 as .git/hooks/pre-commit to prevent this in the future.)

Output from the build log:

python BuildTools\tidy.py
.\ICSharpCode.Decompiler.Tests\TestCases\Pretty\AsyncMain.cs:7: Line starting with spaces. Use tabs for indentation instead!
.\ICSharpCode.Decompiler.Tests\TestCases\Pretty\AsyncMain.cs:13: Line starting with spaces. Use tabs for indentation instead!
Tidy check: failed
Command exited with code 1

@MikeFH
Copy link
Contributor Author

MikeFH commented Jan 15, 2018

Oops, sorry. I thought I was covered with the .editorconfig and VS. I used tidy.py this time.

@siegfriedpammer
Copy link
Member

This happens to us whenever we are adding a new file. Seems to be a bug in VS because the templates do not respect the settings in .editorconfig.

@@ -44,6 +45,11 @@ public static bool IsCompilerGeneratedStateMachine(Mono.Cecil.TypeDefinition typ
return false;
}

public static bool IsCompilerGeneratedMainMethod(MethodDefinition method)
{
return method.Name.Equals("<Main>", StringComparison.Ordinal);
Copy link
Member

@siegfriedpammer siegfriedpammer Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably check, if the method is the entrypoint as well: method.Module.Assembly?.EntryPoint == method. Ideally we should check whether the method body matches the Main(args).GetAwaiter().GetResult(); pattern, but I think this is not easily possible in a static context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I added the check.

@siegfriedpammer siegfriedpammer merged commit fb3e951 into icsharpcode:master Jan 19, 2018
@siegfriedpammer
Copy link
Member

Thank you very much for your contribution to ILSpy!

@MikeFH
Copy link
Contributor Author

MikeFH commented Jan 20, 2018

Thanks, glad I could help.

@MikeFH MikeFH deleted the async-main branch January 20, 2018 15:58
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.

2 participants