Throwaway.CodeAnalysis.Analyzers
1.0.0
dotnet add package Throwaway.CodeAnalysis.Analyzers --version 1.0.0
NuGet\Install-Package Throwaway.CodeAnalysis.Analyzers -Version 1.0.0
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="Throwaway.CodeAnalysis.Analyzers" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Throwaway.CodeAnalysis.Analyzers" Version="1.0.0" />
<PackageReference Include="Throwaway.CodeAnalysis.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
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 Throwaway.CodeAnalysis.Analyzers --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Throwaway.CodeAnalysis.Analyzers, 1.0.0"
#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 Throwaway.CodeAnalysis.Analyzers@1.0.0
#: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=Throwaway.CodeAnalysis.Analyzers&version=1.0.0
#tool nuget:?package=Throwaway.CodeAnalysis.Analyzers&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Throwaway
Exception-free error handling for C#. A lightweight Result pattern library with Roslyn analyzers that guide you toward explicit, composable error handling.
Overview
Throwaway provides:
Result<T>andResulttypes - Explicit success/failure containers that replace exceptions for business logic- Rich composition operators -
Bind,Map,Match,Tap,Combine,TrySelect,OrElse, and more - Heterogeneous Combine - Compose Results of different types into tuples
- Roslyn analyzers with code fixes - Detect anti-patterns and guide refactors in real-time
Installation
dotnet add package Throwaway.Core
dotnet add package Throwaway.CodeAnalysis.Analyzers
Quick Start
using Throwaway.Core;
public Result<User> GetUser(string id)
{
// Explicit success or failure
var userResult = await _db.GetUserAsync(id);
if (userResult == null)
return Result<User>.Failure(Error.NotFound("User not found"));
return Result<User>.Success(userResult);
}
// Consume with explicit handling
userResult.Match(
user => Console.WriteLine($"Hello {user.Name}"),
error => Console.WriteLine($"Error: {error.Message}")
);
// Or pipeline operations
userResult
.Bind(user => LoadPreferences(user.Id))
.Tap(prefs => Console.WriteLine($"Loaded {prefs.Count} preferences"))
.MapError(error => Error.Internal("Failed to load user"));
Heterogeneous Combine
Combine independent Results of different types into a single tuple Result:
using Throwaway.Core;
using static Throwaway.Core.Result;
var nameResult = ValidateName(input.Name);
var emailResult = ValidateEmail(input.Email);
var ageResult = ValidateAge(input.Age);
var combined = Result.Combine(nameResult, emailResult, ageResult);
combined.Match(
(name, email, age) => CreateUser(name, email, age),
error => HandleError(error)
);
Async version with parallel execution:
var combined = await Result.CombineAsync(
ValidateNameAsync(input.Name),
ValidateEmailAsync(input.Email),
ValidateAgeAsync(input.Age)
);
Result Patterns
Bind (chain fallible operations)
userResult
.Bind(user => LoadPreferences(user.Id))
.Bind(prefs => ApplyTheme(prefs.SelectedTheme));
Map (transform success values)
userResult.Map(user => user.Name.ToUpper());
Match (handle both branches)
userResult.Match(
user => $"Hello {user.Name}",
error => $"Error: {error.Message}"
);
Tap (side effects)
userResult.Tap(user => _logger.LogInformation("Got user {UserId}", user.Id));
TrySelect (apply fallible operations to collections)
var userIds = new[] { 1, 2, 3 };
var results = await userIds.TrySelectAsync(id => GetUserAsync(id));
// Returns all successes OR first failure
OrElse (fallback on failure)
var result = await GetFromCacheAsync(key)
.OrElse(() => GetFromDatabaseAsync(key))
.OrElse(() => Result<User>.Success(DefaultUser));
Destructured Binding on Combined Results
Result.Combine(
ValidateName(name),
ValidateEmail(email),
ValidateAge(age)
).Bind((validName, validEmail, validAge) =>
CreateUser(validName, validEmail, validAge)
);
Analyzer Diagnostics
The analyzer package detects and helps fix common anti-patterns:
| ID | Name | Severity | Fix? |
|---|---|---|---|
| THR001 | Unhandled Result | Warning | No |
| THR003 | Result<T> creation not assigned | Info | No |
| THR006 | Unchecked Error access | Warning | No |
| THR300 | Missing failure branch | Warning | No |
| THR306 | Discarded Error in Match | Warning | No |
| THR060 | Combine over Bind staircase | Info | Yes |
| THR061 | Combine over sequential guards | Info | Yes |
| THR062 | Destructured lambda | Info | Yes |
| THR069 | TrySelect over loop | Info | Yes |
| THR070 | OrElse over fallback pattern | Info | Yes |
| THR071 | Combine over tuple assembly | Info | Yes |
Documentation
License
MIT
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
This package has 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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 89 | 3/21/2026 |