< Summary

Information
Class: Anichron.API.Services.ServiceResult
Assembly: Anichron.API
File(s): /home/runner/work/anichron/anichron/src/Anichron.API/Services/ServiceResult.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 36
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Fail(...)100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.API/Services/ServiceResult.cs

#LineLine coverage
 1namespace Anichron.API.Services;
 2
 3public sealed class ServiceResult<T, TError>
 4    where TError : class, IServiceError
 5{
 6    private readonly T? value;
 7    private readonly TError? error;
 8
 9    private ServiceResult(T? value, TError? error)
 10    {
 11        this.value = value;
 12        this.error = error;
 13    }
 14
 15    public bool IsSuccess => error is null;
 16
 17    public static implicit operator ServiceResult<T, TError>(T value)
 18    {
 19        return new(value, null);
 20    }
 21
 22    public static implicit operator ServiceResult<T, TError>(TError error)
 23    {
 24        return new(default, error);
 25    }
 26
 27    public TResult Match<TResult>(Func<T, TResult> ok, Func<TError, TResult> failed)
 28        => error is null ? ok(value!) : failed(error);
 29}
 30
 31public static class ServiceResult
 32{
 33    public static ServiceResult<T, TError> Fail<T, TError>(TError error)
 34        where TError : class, IServiceError
 4035        => error;
 36}

Methods/Properties

Fail(TError)