Skip to content

Commit

Permalink
Add Result.Created void methods so that return Result type is implici…
Browse files Browse the repository at this point in the history
…tly handled. (#200)

* Created methods should use the passed value to correctly create to respective Result<T> response with the set status of ResultStatus.Created

* Reverted changes in order to make use of the Void result

* Added the created methods to the Result.Void class so that it can implicitly convert from the Value to the Result<T> with the Created status set.

---------

Co-authored-by: Steve Smith <[email protected]>
  • Loading branch information
jdrames and ardalis committed Sep 11, 2024
1 parent 8de48b9 commit 194d23c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Ardalis.Result/Result.Void.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ public static Result<T> Success<T>(T value, string successMessage)
return new Result<T>(value, successMessage);
}

/// <summary>
/// Represents a successful operation that resulted in the creation of a new resource.
/// Accepts a value as the result of the operation.
/// </summary>
/// <param name="value">Sets the Value property</param>
/// <returns>A Result<typeparamref name="T"/></returns>
public static Result<T> Created<T>(T value)
{
return Result<T>.Created(value);
}

/// <summary>
/// Represents a successful operation that resulted in the creation of a new resource.
/// Accepts a value as the result of the operation.
/// Accepts a location for the new resource.
/// </summary>
/// <param name="value">Sets the Value property</param>
/// <param name="location">The location of the newly created resource</param>
/// <returns>A Result<typeparamref name="T"/></returns>
public static Result<T> Created<T>(T value, string location)
{
return Result<T>.Created(value, location);
}

/// <summary>
/// Represents an error that occurred during the execution of the service.
/// Error messages may be provided and will be exposed via the Errors property.
Expand Down

0 comments on commit 194d23c

Please sign in to comment.