Nostdlib.Results 0.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Nostdlib.Results --version 0.0.1
                    
NuGet\Install-Package Nostdlib.Results -Version 0.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="Nostdlib.Results" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nostdlib.Results" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Nostdlib.Results" />
                    
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 Nostdlib.Results --version 0.0.1
                    
#r "nuget: Nostdlib.Results, 0.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 Nostdlib.Results@0.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=Nostdlib.Results&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Nostdlib.Results&version=0.0.1
                    
Install as a Cake Tool

Results Library for .NET

Overview

The OperationResult library provides a generic way to represent the outcome of an operation, including success, failure, and partial success. It includes structured information about the status of the operation, any related messages, and the severity of those messages (Information, Warning, or Error).

Features

  • Operation Status: Represents whether the operation was successful, partially successful (with warnings), or failed.
  • Messages: Supports the inclusion of messages that describe the outcome, with specific severities like Information, Warning, and Error.
  • Generics Support: Allows for the use of a value along with the result, useful for when the operation returns a data payload on success.
  • JSON Serialization: The operation result and its messages can be easily serialized and deserialized for use in APIs or other external systems.

Classes Overview

OperationResult

Represents the outcome of an operation, encapsulating success, failure, or partial success. It includes a list of messages and their severities.

public record class OperationResult
{
    public virtual bool Succeeded { get; }
    public virtual bool HasWarnings() => FindWarnings().Any();
    public virtual bool HasErrors() => FindErrors().Any();
    public ImmutableList<OperationResultMessage> Messages { get; init; }
    public static OperationResult Success(params OperationResultMessage[] messages) => new SuccessfulOperationResult(messages);
    public static OperationResult Failure(params OperationResultMessage[] errors) => new FailedOperationResult(errors);
}

SuccessfulOperationResult

A subclass of OperationResult that represents a successful operation result.

public record SuccessfulOperationResult : OperationResult
{
    public override bool Succeeded { get; } = true;
}

FailedOperationResult

A subclass of OperationResult that represents a failed operation result.

public record FailedOperationResult : OperationResult
{
    public override bool Succeeded { get; } = false;
}

OperationResultMessage

Represents a message that is part of the operation result, including a message string and severity level.

public record class OperationResultMessage
{
    public string Message { get; }
    public OperationResultSeverity Severity { get; }
}

OperationResultSeverity

An enum that defines the severity levels for operation result messages.

public enum OperationResultSeverity
{
    Information,
    Warning,
    Error
}

OperationResultStatus

An enum that defines the status of the operation.

public enum OperationResultStatus
{
    Success,
    Failure,
    PartialSuccess
}

OperationResult<T>

A generic version of OperationResult that holds a value along with the result.

public record class OperationResult<T> : OperationResult
{
    public T? Value { get; init; }
    public static OperationResult<T> Success(T? value, params OperationResultMessage[] messages) => new SuccessfulOperationResult<T>(value, messages);
    public static OperationResult<T> Failure(params OperationResultMessage[] messages) => new FailedOperationResult<T>(messages);
}

SuccessfulOperationResult<T>

A subclass of OperationResult<T> that represents a successful operation result with a value.

public record SuccessfulOperationResult<T> : OperationResult<T>
{
    public override bool Succeeded { get; } = true;
}

FailedOperationResult<T>

A subclass of OperationResult<T> that represents a failed operation result with a value.

public record class FailedOperationResult<T> : OperationResult<T>
{
    public override bool Succeeded { get; } = false;
}

Notes

  • The OperationResult is designed to handle both simple and complex scenarios with and without additional data.
  • Custom message severities and statuses are supported, providing flexible control over the output of operations.
  • JSON serialization is supported for easy integration into APIs and external systems.
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 was computed.  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 was computed.  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.
  • net8.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.

Version Downloads Last Updated