-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToOkHttpResultTE.cs
More file actions
27 lines (24 loc) · 1.04 KB
/
ToOkHttpResultTE.cs
File metadata and controls
27 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace CSharpFunctionalExtensions.HttpResults.Generators.ResultExtensions;
internal class ToOkHttpResultTE : IGenerateMethods
{
public string Generate(string mapperClassName, string resultErrorType, string httpResultType)
{
return $$"""
/// <summary>
/// Returns a <see cref="Ok{TValue}"/> in case of success result. Returns custom mapping in case of failure.
/// </summary>
public static Results<Ok<T>, {{httpResultType}}> ToOkHttpResult<T>(this Result<T,{{resultErrorType}}> result)
{
if (result.IsSuccess) return TypedResults.Ok(result.Value);
return ErrorMapperInstances.{{mapperClassName}}.Map(result.Error);
}
/// <summary>
/// Returns a <see cref="Ok{TValue}"/> in case of success result. Returns custom mapping in case of failure.
/// </summary>
public static async Task<Results<Ok<T>, {{httpResultType}}>> ToOkHttpResult<T>(this Task<Result<T,{{resultErrorType}}>> result)
{
return (await result).ToOkHttpResult();
}
""";
}
}