Skip to content

Commit

Permalink
Fixed fluent methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiryuumaru committed Feb 15, 2024
1 parent 3117e04 commit 2893850
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions TransactionHelpers/Interface/IResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using TransactionHelpers.Exceptions;
using System.Text.Json.Serialization;

namespace TransactionHelpers.Interface;

Expand All @@ -12,6 +13,7 @@ public interface IResult
/// <summary>
/// Gets the last <see cref="TransactionHelpers.Error"/> of the operation.
/// </summary>
[JsonIgnore]
Error? Error { get; }

/// <summary>
Expand All @@ -29,6 +31,7 @@ public interface IResult
/// Gets <c>true</c> whether the operation is successful; otherwise, <c>false</c>.
/// </summary>
[MemberNotNullWhen(true, nameof(Error))]
[JsonIgnore]
bool IsError { get; }

/// <summary>
Expand Down Expand Up @@ -57,6 +60,7 @@ public interface IResult<TValue> : IResult
/// Gets <c>true</c> whether the <see cref="IResult{TValue}.Value"/> no has value; otherwise, <c>false</c>.
/// </summary>
[MemberNotNullWhen(false, nameof(Value))]
[JsonIgnore]
bool HasNoValue { get; }

/// <summary>
Expand Down
22 changes: 22 additions & 0 deletions TransactionHelpers/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ public virtual void ThrowIfError()
{
return new Result().WithError(exception);
}

/// <summary>
/// Implicit operator for <see cref="Result{TValue}"/> to <see cref="Error"/> conversion.
/// </summary>
/// <param name="result">
/// The <see cref="Result{TValue}"/> to convert.
/// </param>
public static implicit operator Error?(Result result)
{
return result.Error;
}

/// <summary>
/// Implicit operator for <see cref="Result{TValue}"/> to <see cref="Exception"/> conversion.
/// </summary>
/// <param name="result">
/// The <see cref="Result{TValue}"/> to convert.
/// </param>
public static implicit operator Exception?(Result result)
{
return result.Error?.Exception;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion TransactionHelpers/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.0.9
2.0.10
* Fixed fluent methods

0 comments on commit 2893850

Please sign in to comment.