feat: initial project commit
Some checks failed
dotnet publish / package (8.0) (push) Failing after 8s
Some checks failed
dotnet publish / package (8.0) (push) Failing after 8s
This commit is contained in:
commit
87a93fa2df
39 changed files with 3658 additions and 0 deletions
63
src/Results/Result.Unbox.cs
Normal file
63
src/Results/Result.Unbox.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Geekeey.Common.Results;
|
||||
|
||||
public readonly partial struct Result<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to get the success value from the result.
|
||||
/// </summary>
|
||||
/// <param name="value">The success value of the result.</param>
|
||||
/// <returns>Whether the result has success value.</returns>
|
||||
[Pure]
|
||||
public bool TryGetValue([MaybeNullWhen(false)] out T value)
|
||||
{
|
||||
value = Value!;
|
||||
|
||||
return _success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the success value from the result.
|
||||
/// </summary>
|
||||
/// <param name="value">The success value of the result.</param>
|
||||
/// <param name="error">The failure value of the result.</param>
|
||||
/// <returns>Whether the result has a success value.</returns>
|
||||
[Pure]
|
||||
public bool TryGetValue([MaybeNullWhen(false)] out T value, [MaybeNullWhen(true)] out Error error)
|
||||
{
|
||||
value = Value!;
|
||||
error = !_success ? Error : null!;
|
||||
|
||||
return _success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the failure value from the result.
|
||||
/// </summary>
|
||||
/// <param name="error">The failure value of the result.</param>
|
||||
/// <returns>Whether the result has a failure value.</returns>
|
||||
[Pure]
|
||||
public bool TryGetError([MaybeNullWhen(false)] out Error error)
|
||||
{
|
||||
error = !_success ? Error : null!;
|
||||
|
||||
return !_success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the failure value from the result.
|
||||
/// </summary>
|
||||
/// <param name="error">The failure value of the result.</param>
|
||||
/// <param name="value">The success value of the result.</param>
|
||||
/// <returns>Whether the result a failure value.</returns>
|
||||
[Pure]
|
||||
public bool TryGetError([MaybeNullWhen(false)] out Error error, [MaybeNullWhen(true)] out T value)
|
||||
{
|
||||
error = !_success ? Error : null!;
|
||||
value = Value!;
|
||||
|
||||
return !_success;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue