{"repo":"zompinc/sync-method-generator","free":true,"listed":false,"github":"https://github.com/zompinc/sync-method-generator","clone":"git clone https://github.com/zompinc/sync-method-generator.git","description":"Generates a synchronized version of an async method","language":"C#","stars":83,"topics":["async","async-await","code-generation","codegen","csharp","dotnet","roslyn","roslyn-source-generator","source-generator","source-generators"],"license":"MIT","category":"dev-tools","readme_excerpt":"Sync Method Generator This .NET source generator produces a sync method from an async one. ⭐ Star this project if you hate code duplication or calling async methods from sync. Use cases - A library which exposes both sync and async version of a method - An application has to process two kinds of data in the same way: - Large data from I/O which cannot be stored in memory before processing: Original async method - Small sample of data in memory, usually a sample of the larger data: Generated sync method Used by - FluentValidation - validation library - MiniExcel - spreadsheet reader and writer - SharpCompress - compression library SharpCompress's migration notes are worth reading before adopting this in a codebase which already has both halves written by hand. They cover how to prove that a generated method is the one it replaces, and when attributing a method would add a member rather than remove a duplicate - a generated Read(Span ) displaces the shim Stream provides, which is a change in behaviour rather than a deduplication. How it works CreateSyncVersionAttribute on a method Decorate your async method with CreateSyncVersionAttribute in your partial class, struct, record, or interface: and it will generate a sync version of the method: A list of changes applied to the new synchronized method: - Remove async modifier - Remove await from methods as well as foreach statement - Change types From To -------------------------------------------------------------------------------","default_branch":null,"files":null,"tree":[],"storefront":"/r/zompinc","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/zompinc/sync-method-generator/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}