Skip to content

Commit

Permalink
Fixed Generic Result class return types and Added parameter to static…
Browse files Browse the repository at this point in the history
… generic success metod
  • Loading branch information
NickKvizhinadze committed May 15, 2020
1 parent b4df3de commit 62acf84
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions DotNetHelpers/Models/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,18 @@ public static Result Unauthorized()
/// <summary>
/// Returns result class instance with success
/// </summary>
/// <param name="data">Data</param>
/// <typeparam name="T">Type of data property</typeparam>
/// <returns></returns>
public static Result Success<T>() => new Result<T>();
public static Result<T> Success<T>(T data) => new Result<T>(data);

/// <summary>
/// Returns result class instance with error
/// </summary>
/// <typeparam name="T">Type of data property</typeparam>
/// <param name="errorMessage">Error message</param>
/// <returns></returns>
public static Result Error<T>(string errorMessage)
public static Result<T> Error<T>(string errorMessage)
{
var result = new Result<T>();
result.AddError(errorMessage);
Expand All @@ -185,7 +186,7 @@ public static Result Error<T>(string errorMessage)
/// <typeparam name="T">Type of data property</typeparam>
/// <param name="errorMessage">Error message</param>
/// <returns></returns>
public static Result Throw<T>(string errorMessage)
public static Result<T> Throw<T>(string errorMessage)
{
var result = new Result<T>();
result.AddError(errorMessage, ErrorStatus.Server);
Expand All @@ -197,7 +198,7 @@ public static Result Throw<T>(string errorMessage)
/// </summary>
/// <typeparam name="T">Type of data property</typeparam>
/// <returns></returns>
public static Result Unauthorized<T>()
public static Result<T> Unauthorized<T>()
{
var result = new Result<T>();
result.AddError("Unauthorized", ErrorStatus.UnAuthorized);
Expand All @@ -212,6 +213,22 @@ public static Result Unauthorized<T>()
/// <typeparam name="T">Type of result data</typeparam>
public class Result<T> : Result
{
#region Constructor
/// <summary>
/// Empty Constructor
/// </summary>
public Result()
{
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="data">Data</param>
public Result(T data)
{
Data = data;
}
#endregion
/// <summary>
/// Data to return from method
/// </summary>
Expand Down

0 comments on commit 62acf84

Please sign in to comment.