< Summary

Information
Class: AsiBackbone.Core.Results.OperationResult<T>
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Results/OperationResultOfT.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 53
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%
.ctor(...)100%11100%
get_Value()100%22100%
get_HasValue()100%11100%
get_ValueCore()100%11100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Results/OperationResultOfT.cs

#LineLine coverage
 1namespace AsiBackbone.Core.Results;
 2
 3/// <summary>
 4/// Represents the framework-neutral outcome of an operation that may return a value.
 5/// </summary>
 6/// <typeparam name="TValue">The result value type.</typeparam>
 7public sealed class OperationResult<TValue> : OperationResult
 8{
 9    /// <summary>
 10    /// Initializes a new successful instance of the <see cref="OperationResult{TValue}"/> class.
 11    /// </summary>
 12    /// <param name="value">The operation value.</param>
 13    /// <param name="reasons">The reasons associated with the operation result.</param>
 14    /// <param name="warnings">The warnings associated with the operation result.</param>
 15    internal OperationResult(
 16        TValue value,
 17        IReadOnlyList<OperationReason> reasons,
 18        IReadOnlyList<string> warnings)
 2819        : base(true, reasons, warnings)
 20    {
 2821        ValueCore = value;
 2822    }
 23
 24    /// <summary>
 25    /// Initializes a new failed instance of the <see cref="OperationResult{TValue}"/> class.
 26    /// </summary>
 27    /// <param name="reasons">The reasons associated with the operation result.</param>
 28    /// <param name="warnings">The warnings associated with the operation result.</param>
 29    internal OperationResult(
 30        IReadOnlyList<OperationReason> reasons,
 31        IReadOnlyList<string> warnings)
 932        : base(false, reasons, warnings)
 33    {
 934        ValueCore = default!;
 935    }
 36
 37    /// <summary>
 38    /// Gets the successful operation value.
 39    /// </summary>
 40    /// <exception cref="InvalidOperationException">
 41    /// Thrown when the operation result is failed and no successful value is available.
 42    /// </exception>
 443    public TValue Value => Succeeded
 444        ? ValueCore
 445        : throw new InvalidOperationException("Cannot access the value of a failed operation result.");
 46
 47    /// <summary>
 48    /// Gets a value indicating whether a successful result value is available.
 49    /// </summary>
 550    public bool HasValue => Succeeded;
 51
 352    private TValue ValueCore { get; }
 53}