added missing Append extensions
All checks were successful
.NET Test / test (push) Successful in 3m18s
.NET Publish / publish (push) Successful in 3m28s

This commit is contained in:
2023-12-12 19:02:11 +04:00
parent 9ae185342b
commit b8ea74ec5b
6 changed files with 299 additions and 88 deletions

View File

@@ -200,6 +200,48 @@ internal sealed class ResultAppendExecutor : ResultExtensionsExecutor
string resultExpandedTypeDef = GenerateResultTypeDef(expandedTemplateArgNames);
string methodExpandedTemplateDecl = GenerateTemplateDecl(expandedTemplateArgNames);
sb.AppendLine($$"""
[PureAttribute]
[GeneratedCodeAttribute("{{nameof(ResultAppendExecutor)}}", "1.0.0.0")]
public static async {{taskType}}<{{resultExpandedTypeDef}}> Append{{methodExpandedTemplateDecl}}(this {{taskType}}<{{resultTypeDef}}> resultTask, TNext next)
{
var result = await resultTask.ConfigureAwait(false);
return result.State switch
{
ResultState.Success => Result.Success({{JoinArguments(resultValueExpansion, "next")}}),
ResultState.Error => result.Error!,
_ => throw new ResultNotInitializedException(nameof(result))
};
}
""");
sb.AppendLine($$"""
[PureAttribute]
[GeneratedCodeAttribute("{{nameof(ResultAppendExecutor)}}", "1.0.0.0")]
public static async {{taskType}}<{{resultExpandedTypeDef}}> Append{{methodExpandedTemplateDecl}}(this {{taskType}}<{{resultTypeDef}}> resultTask, Result<TNext> next)
{
var result = await resultTask.ConfigureAwait(false);
if ((result.State & next.State) == ResultState.Bottom)
{
throw new ResultNotInitializedException(string.Join(';', GetBottom(result.State, next.State)));
}
Error? error = null;
if (result.IsFailure)
{
error += result.Error;
}
if (next.IsFailure)
{
error += next.Error;
}
return error is null
? Result.Success({{JoinArguments(resultValueExpansion, "next.Value")}})
: error;
}
""");
sb.AppendLine($$"""
[PureAttribute]
[GeneratedCodeAttribute("{{nameof(ResultAppendExecutor)}}", "1.0.0.0")]