feat: create request projects for basic CQRS
All checks were successful
default / dotnet-default-workflow (push) Successful in 2m0s
All checks were successful
default / dotnet-default-workflow (push) Successful in 2m0s
This commit is contained in:
commit
e1e02c44a0
190 changed files with 12235 additions and 0 deletions
64
src/request.result/Result.Conversion.cs
Normal file
64
src/request.result/Result.Conversion.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Geekeey.Request.Result;
|
||||
|
||||
public partial class Result
|
||||
{
|
||||
/// <summary>
|
||||
/// Implicitly constructs a result from a failure value.
|
||||
/// </summary>
|
||||
/// <param name="error">The error to construct the result from.</param>
|
||||
[Pure]
|
||||
public static implicit operator Result(Error error)
|
||||
{
|
||||
return new Result(error);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Result<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Implicitly constructs a result from a success value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to construct the result from.</param>
|
||||
[Pure]
|
||||
public static implicit operator Result<T>(T value)
|
||||
{
|
||||
return new Result<T>(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly constructs a result from a failure value.
|
||||
/// </summary>
|
||||
/// <param name="error">The error to construct the result from.</param>
|
||||
[Pure]
|
||||
public static implicit operator Result<T>(Error error)
|
||||
{
|
||||
return new Result<T>(error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unwraps the success value of the result. Throws an <see cref="UnwrapException"/> if the result is a failure.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This call is <b>unsafe</b> in the sense that it might intentionally throw an exception. Please only use this
|
||||
/// call if the caller knows that this operation is safe, or that an exception is acceptable to be thrown.
|
||||
/// </remarks>
|
||||
/// <returns>The success value of the result.</returns>
|
||||
/// <exception cref="UnwrapException">The result is not a success.</exception>
|
||||
[Pure]
|
||||
public T Unwrap()
|
||||
{
|
||||
return IsSuccess ? Value : throw new UnwrapException();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Unwrap"/>
|
||||
[Pure]
|
||||
public static explicit operator T(Result<T> result)
|
||||
{
|
||||
return result.Unwrap();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue