Swevo.AutoResult
1.0.1
Prefix Reserved
dotnet add package Swevo.AutoResult --version 1.0.1
NuGet\Install-Package Swevo.AutoResult -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Swevo.AutoResult" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Swevo.AutoResult" Version="1.0.1" />
<PackageReference Include="Swevo.AutoResult" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Swevo.AutoResult --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Swevo.AutoResult, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Swevo.AutoResult@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Swevo.AutoResult&version=1.0.1
#tool nuget:?package=Swevo.AutoResult&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AutoResult.Generator
A Roslyn source generator that automatically wraps your methods in Result<T> — zero reflection, zero runtime overhead, compile-time safe.
Features
- 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
Installation
dotnet add package AutoResult.Generator
Usage
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); }
}
}
Core Types
// 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
Diagnostics
| Code | Severity | Description |
|---|---|---|
| AR001 | Error | [TryWrap] applied to a non-partial class |
| AR002 | Warning | [TryWrap] class has no wrappable public methods |
Why AutoResult?
- 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
Also by the same author
🌐 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. |
License
MIT
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.0: Result<T>/Result<T,TError>/Unit types + ResultExtensions always emitted. [TryWrap] generates Try*() wrappers for sync, async and void methods.