Files
Musify/Musify.Application/Extensions/ResultExtensions.cs
T
Admin 3be31a6378 refactor: standardize project names to Musify.* and flatten layout
- Flatten nested per-repo folders into flat Musify.* projects at root
- Rename assemblies/csproj: Domain->Musify.Domain, Application->Musify.Application,
  Infrastructure->Musify.Infrastructure, WebApi->Musify.Api, Worker->Musify.Worker,
  StreamingGateway->Musify.StreamingGateway
- Rename WebApi.* namespaces to Musify.Api.*
- Update all ProjectReference paths and the solution file
- Consolidate stray per-repo dotfiles; add root .gitattributes
- Move flutter client out to _archive
2026-07-05 03:32:48 +02:00

25 lines
1.3 KiB
C#

using Ardalis.Result;
namespace Musify.Application.Extensions;
public static class ResultExtensions
{
public static Result<TOut> As<TIn, TOut>(this Result<TIn> result)
{
return result.Status switch
{
ResultStatus.Ok or
ResultStatus.Created or
ResultStatus.NoContent => throw new InvalidOperationException($"Cannot convert a successful result ( {result.Status} ) to another type. Use Map or Bind instead."),
ResultStatus.NotFound => Result<TOut>.NotFound(result.Errors.ToArray()),
ResultStatus.Forbidden => Result<TOut>.Forbidden(result.Errors.ToArray()),
ResultStatus.Unauthorized => Result<TOut>.Unauthorized(result.Errors.ToArray()),
ResultStatus.Invalid => Result<TOut>.Invalid(result.ValidationErrors.ToArray()),
ResultStatus.Conflict => Result<TOut>.Conflict(result.Errors.ToArray()),
ResultStatus.CriticalError => Result<TOut>.CriticalError(result.Errors.ToArray()),
ResultStatus.Unavailable => Result<TOut>.Unavailable(result.Errors.ToArray()),
ResultStatus.Error => Result<TOut>.Error(string.Join(";", result.Errors)),
_ => Result<TOut>.Error(string.Join(";", result.Errors))
};
}
}