Nostdlib.Results
0.0.1
dotnet add package Nostdlib.Results --version 0.0.1
NuGet\Install-Package Nostdlib.Results -Version 0.0.1
<PackageReference Include="Nostdlib.Results" Version="0.0.1" />
<PackageVersion Include="Nostdlib.Results" Version="0.0.1" />
<PackageReference Include="Nostdlib.Results" />
paket add Nostdlib.Results --version 0.0.1
#r "nuget: Nostdlib.Results, 0.0.1"
#:package Nostdlib.Results@0.0.1
#addin nuget:?package=Nostdlib.Results&version=0.0.1
#tool nuget:?package=Nostdlib.Results&version=0.0.1
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 | Versions 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. |
-
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 |
|---|