< Summary

Information
Class: MyNet.Primitives.FallbackValue<T>
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Models/FallbackValue.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 44
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
get_Value()100%22100%
SetOverride(...)100%11100%
ResetOverride()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Models/FallbackValue.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FallbackValue.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9#pragma warning disable IDE0130 // Namespace does not match folder structure
 10namespace MyNet.Primitives;
 11#pragma warning restore IDE0130 // Namespace does not match folder structure
 12
 13/// <summary>
 14/// Represents a value that can be obtained from a primary source, but falls back to an alternative source if the primar
 15/// </summary>
 16/// <param name="fallback">The fallback source function.</param>
 17/// <typeparam name="T">The type of the value.</typeparam>
 18public class FallbackValue<T>(Func<T?> fallback)
 19{
 20    private bool _hasOverride;
 21    private T? _override;
 22
 1223    public T? Value => _hasOverride ? _override : fallback.Invoke();
 24
 25    /// <summary>
 26    /// Sets an override value that takes precedence over both the primary and fallback sources. Once set, this value wi
 27    /// </summary>
 28    /// <param name="value">The override value to set.</param>
 29    public void SetOverride(T value)
 30    {
 631        _override = value;
 632        _hasOverride = true;
 633    }
 34
 35    /// <summary>
 36    /// Resets the override value, allowing the primary and fallback sources to determine the value again. After calling
 37    /// </summary>
 38    public void ResetOverride()
 39    {
 340        _override = default;
 341        _hasOverride = false;
 342    }
 43}
 44