NuGet NuGet Downloads CI License: MIT .NET 10 Ready
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.AutoResult
using AutoResult; [TryWrap] public partial class OrderService { public int GetOrderId(string name) => // ... public async Task<Order> FetchOrderAsync(int id) => // ... public void ProcessOrder(Order order) => // ... }
The generator produces:
public partial class OrderService { public Result<int> TryGetOrderId(string name) { try { return Result<int>.Ok(GetOrderId(name)); } catch (Exception ex) { return Result<int>.Fail(ex); } } public async Task<Result<Order>> TryFetchOrderAsync(int id) { try { return Result<Order>.Ok(await FetchOrderAsync(id)); } catch (Exception ex) { return Result<Order>.Fail(ex); } } public Result<Unit> TryProcessOrder(Order order) { try { ProcessOrder(order); return Result<Unit>.Ok(Unit.Value); } catch (Exception ex) { return Result<Unit>.Fail(ex); } } }
// Always available — no extra imports needed Result<T>.Ok(value) Result<T>.Fail(exception) Result<T>.IsSuccess / .IsFailure Result<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 | Downloads | Free, MIT-licensed in-process message bus for |
| Swevo.AutoBus.RabbitMQ | Downloads | RabbitMQ transport for AutoBus |
| Swevo.AutoAssert | Downloads | Free, MIT-licensed fluent assertions for |
| Swevo.AutoAuth | Downloads | A free, MIT-licensed fluent configuration wrapper around OpenIddict for building OAuth2/OIDC token servers in ASP |
| Swevo.AutoAudit | Downloads | Compile-time audit field generation for EF Core entities using Roslyn source generators |
| Swevo.AutoGuard | Downloads | Compile-time guard clauses for |
| Swevo.AutoImage | Downloads | A free, MIT-licensed fluent image processing wrapper around SkiaSharp for |
| Swevo.AutoFeatureFlag | Downloads | Compile-time feature flag stubs for |
| Swevo.AutoTestData | Downloads | Compile-time test data builders for |
MIT