A Roslyn source generator that automatically wraps your methods in Result<T> — zero reflection, zero runtime overhead, compile-time safe.
- Core Result types always generated:
Result<T>,Result<T,TError>,Unit,ResultExtensions [TryWrap]generatesTry*()variants for every public method in your partial class- Supports sync, void, async, and async-void methods
- Compile-time diagnostics for misuse
dotnet add package Swevo.AutoResultusingAutoResult;[TryWrap]publicpartialclassOrderService{publicintGetOrderId(stringname)=>// ...publicasync Task<Order> FetchOrderAsync(intid)=>// ...publicvoid ProcessOrder(Orderorder)=>// ...}The generator produces:
publicpartialclassOrderService{publicResult<int>TryGetOrderId(stringname){try{returnResult<int>.Ok(GetOrderId(name));}catch(Exceptionex){returnResult<int>.Fail(ex);}}publicasyncTask<Result<Order>>TryFetchOrderAsync(intid){try{returnResult<Order>.Ok(awaitFetchOrderAsync(id));}catch(Exceptionex){returnResult<Order>.Fail(ex);}}publicResult<Unit>TryProcessOrder(Orderorder){try{ProcessOrder(order);returnResult<Unit>.Ok(Unit.Value);}catch(Exceptionex){returnResult<Unit>.Fail(ex);}}}// Always available — no extra imports neededResult<T>.Ok(value)Result<T>.Fail(exception)Result<T>.IsSuccess/.IsFailureResult<T>.Value /.Error
Result<T,TError>.Ok(value)
Result<T,TError>.Fail(error)
Unit.Value // for void-returning methods| Code | Severity | Description |
|---|---|---|
| AR001 | Error | [TryWrap] applied to a non-partial class |
| AR002 | Warning | [TryWrap] class has no wrappable public methods |
- Zero overhead — wrapper code is generated at compile time
- No boilerplate — stop writing the same try/catch in every service
- Railway-oriented — compose results cleanly with
Map,Bind,Match - Minimal API — no third-party Result library required; types live in your project
🌐 Full suite overview: swevo.github.io
| Package | Description |
|---|---|
| AutoWire | Compile-time DI auto-registration — [Scoped]/[Singleton]/[Transient] generates IServiceCollection code. Zero reflection. |
| AutoMap.Generator | Compile-time object mapping — [Map(typeof(Dto))] generates ToDto() extension methods. Zero reflection, AOT-safe. |
| AutoValidate.Generator | Compile-time FluentValidation wiring — discovers AbstractValidator<T> subclasses and generates AddValidators(). |
| AutoQuery.Generator | Compile-time LINQ query specs — [QuerySpec(typeof(T))] generates Apply(IQueryable<T>). |
| AutoDispatch.Generator | Compile-time CQRS dispatcher — [Handler] generates a strongly-typed IDispatcher. No IRequest<T>, no reflection. |
| AutoLog.Generator | Compile-time high-performance logging — [Log(Level, Message)] on a partial method generates LoggerMessage.Define. AOT-safe. |
| AutoHttpClient.Generator | Compile-time typed HTTP client — [HttpClient] on an interface generates a strongly-typed client. AOT-safe Refit alternative. |
| Package | Downloads | Description |
|---|---|---|
| Swevo.AutoBus | Free, MIT-licensed in-process message bus for | |
| Swevo.AutoBus.RabbitMQ | RabbitMQ transport for AutoBus | |
| Swevo.AutoAssert | Free, MIT-licensed fluent assertions for | |
| Swevo.AutoAuth | A free, MIT-licensed fluent configuration wrapper around OpenIddict for building OAuth2/OIDC token servers in ASP | |
| Swevo.AutoAudit | Compile-time audit field generation for EF Core entities using Roslyn source generators | |
| Swevo.AutoGuard | Compile-time guard clauses for | |
| Swevo.AutoImage | A free, MIT-licensed fluent image processing wrapper around SkiaSharp for | |
| Swevo.AutoFeatureFlag | Compile-time feature flag stubs for | |
| Swevo.AutoTestData | Compile-time test data builders for |
MIT