Megaraz.ResultPattern 0.2.2

dotnet add package Megaraz.ResultPattern --version 0.2.2
                    
NuGet\Install-Package Megaraz.ResultPattern -Version 0.2.2
                    
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="Megaraz.ResultPattern" Version="0.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Megaraz.ResultPattern" Version="0.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Megaraz.ResultPattern" />
                    
Project file
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 Megaraz.ResultPattern --version 0.2.2
                    
#r "nuget: Megaraz.ResultPattern, 0.2.2"
                    
#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 Megaraz.ResultPattern@0.2.2
                    
#: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=Megaraz.ResultPattern&version=0.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Megaraz.ResultPattern&version=0.2.2
                    
Install as a Cake Tool

Megaraz.ResultPattern

Megaraz.ResultPattern is a focused .NET library for representing successful operations, failures, and validation errors without coupling consumers to web or persistence frameworks.

var result = Result<string>.Success("value");

if (result.IsSuccess)
{
    Console.WriteLine(result.Value);
}

Successful Result<TValue> instances require a non-null value. Failed results expose a PrimaryError, while validation failures also expose their ValidationErrors.

Support and compatibility

The package supports .NET 8, .NET 9, and .NET 10. It follows semantic versioning: patch releases contain compatible fixes, minor releases may add backward-compatible functionality, and major releases may contain breaking changes. Error codes are machine-readable contracts and should be treated as stable by consumers.

Use this core package for framework-agnostic result and error modeling. Use an extension package when an integration needs framework, transport, persistence, or other external-system details; those details intentionally do not belong in the core package.

Error codes

Built-in factories retain conventional codes such as Create.User.NotFound. For application-owned contracts, provide any stable code directly; the library does not require an Operation.Entity.Reason format:

var error = Error.Custom(
    ErrorCode.From("accounts.email-already-registered"),
    "The email address is already registered.",
    ErrorType.Conflict);

var validationError = ValidationError.CustomWithReason(
    new ErrorContext(OperationType.Create, "User", "Email"),
    "EmailAlreadyRegistered",
    "The email address is already registered.");

CustomWithReason is an opt-in convenience that produces Create.User.EmailAlreadyRegistered; use ErrorCode.From when the code shape is owned by your application.

Extension errors

ErrorType.External is intended for errors supplied by extension packages or external dependencies. Extension packages can derive from Error and expose their own detailed error enum while using External as the shared top-level classification:

var error = Error.Custom(
    ErrorCode.From("payments.gateway-timeout"),
    "The payment gateway did not respond in time.",
    ErrorType.External);

ErrorContext requires a defined operation and a non-blank logical entity or resource name. Its optional FieldName is metadata for validation and presentation; it is not part of conventional error codes and may use labels such as Profile.Email. These invariants are enforced during construction and when creating record copies with with expressions.

Built-in error factories provide technical fallback descriptions, but do not assume a presentation language: UserMessage is empty unless supplied. Use the optional messageFactory argument to create localized or application-specific descriptions in an extension or application layer.

Custom validation factories follow the same safe default: their description is diagnostic detail and is not copied to UserMessage. Supply userMessage explicitly when a presentation-safe message is intended.

For validation, the Validate... methods return a ValidationError when a check fails and null when it passes:

var error = email.ValidateRequired(context, "Email");
if (error is not null)
    return Result.ValidationFailure([error]);

The existing boolean validation methods remain available for compatibility and return true when the invalid condition is detected.

Install from NuGet:

dotnet add package Megaraz.ResultPattern

Security

Please report suspected vulnerabilities privately through GitHub Security Advisories. Do not include exploit details in public issues.

License

Megaraz.ResultPattern is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Megaraz.ResultPattern:

Package Downloads
Megaraz.ResultPattern.AspNetCore

ASP.NET Core and HTTP extensions for Megaraz.ResultPattern.

Megaraz.ResultPattern.Infrastructure

Provider-neutral infrastructure error extensions for Megaraz.ResultPattern.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2 636 7/26/2026
0.2.1 108 7/26/2026
0.2.0 138 7/25/2026
0.1.0 112 7/25/2026

0.2.2: Combines the pending post-0.2.1 maintenance changes: validation and error-context invariant fixes, clearer validation and security documentation, package metadata and release-version validation, portable symbol packages, Source Link and package-content verification, CI artifact retention, and immutable GitHub Actions pins. The boolean validation out-parameter nullable annotations remain unchanged from 0.2.1 for source compatibility; their values are meaningful only when the method returns true.