Skip to content

Commit

Permalink
Added GetValueOrThrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiryuumaru committed Apr 22, 2024
1 parent 3d9b5fe commit 0502cc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions TransactionHelpers/Interface/IResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ public interface IResult<TValue> : IResult
/// <exception cref="EmptyResultException">the <see cref="IResult{TValue}.Value"/> has no value.</exception>
[MemberNotNull(nameof(Value))]
void ThrowIfErrorOrHasNoValue();

/// <summary>
/// Get value or throws if the result has any _error or has no value.
/// </summary>
/// <exception cref="EmptyResultException">the <see cref="IResult{TValue}.Value"/> has no value.</exception>
[MemberNotNull(nameof(Value))]
TValue GetValueOrThrow();
}
8 changes: 8 additions & 0 deletions TransactionHelpers/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public virtual void ThrowIfErrorOrHasNoValue()
}
}

/// <inheritdoc/>
[MemberNotNull(nameof(Value))]
public virtual TValue GetValueOrThrow()
{
ThrowIfErrorOrHasNoValue();
return Value;
}

/// <summary>
/// Implicit operator for <see cref="Error"/> conversion.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions TransactionHelpers/version.txt

This file was deleted.

0 comments on commit 0502cc9

Please sign in to comment.