< Summary

Information
Class: Anichron.API.Services.ServiceResult<T1, T2>
Assembly: Anichron.API
File(s): /home/runner/work/anichron/anichron/src/Anichron.API/Services/ServiceResult.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 36
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_IsSuccess()100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
Match(...)100%22100%

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
 1779    private ServiceResult(T? value, TError? error)
 17710    {
 17711        this.value = value;
 17712        this.error = error;
 17713    }
 14
 6515    public bool IsSuccess => error is null;
 16
 17    public static implicit operator ServiceResult<T, TError>(T value)
 7918    {
 7919        return new(value, null);
 7920    }
 21
 22    public static implicit operator ServiceResult<T, TError>(TError error)
 9823    {
 9824        return new(default, error);
 9825    }
 26
 27    public TResult Match<TResult>(Func<T, TResult> ok, Func<TError, TResult> failed)
 21328        => 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
 35        => error;
 36}