Clone this wiki locally
Shaolinq.AsynRewriter automatically converts your sync methods into async methods using the Roslyn compiler to parse and generate equivalent async code. Library developers quickly realise that the code for async is pretty much the same as their sync code except that calls to
Method1() are replaced with
await Method1Async() calls which results in a lot of copy & paste code. Shaolinq.AsyncRewriter solves this issue by generating the code for you.
Shaolinq.AsyncRewriter is available as a NuGet package (Shaolinq.AsyncRewriter). Create a new class library project and then add the Shaolinq.AsyncRewriter NuGet Package. The package will automatically add some pre-build steps to your
csproj to generate the async code before the full compile. Additionally the package will add a class named RewriteAsyncAttribute to your project. Simply decorate any method in your project with the
[RewriteAsync] attribute to have an equivalent async method generated. You will need to make sure any types containing
[RewriteAsync] are declared as
partial because AsyncRewriter will add async methods to the type by outputting matching
How it works
AsyncRewriter will generate a source file named
GeneratedAsync.cs. All types with methods attributed with
[RewriteAsync] will get equivalent async methods (two async methods for each sync method) outputted into
All methods are translated as follows:
For each attributed sync method two methods are generated with the name and "Async" appended.