< Summary

Information
Class: Allyaria.Abstractions.Extensions.GenericExtensions
Assembly: Allyaria.Abstractions
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Abstractions/Extensions/GenericExtensions.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 26
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
OrDefault(...)100%11100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Abstractions/Extensions/GenericExtensions.cs

#LineLine coverage
 1namespace Allyaria.Abstractions.Extensions;
 2
 3/// <summary>
 4/// Provides generic extension methods focused on nullable value types, enabling convenient defaults when a value is not
 5/// present.
 6/// </summary>
 7public static class GenericExtensions
 8{
 9    /// <summary>
 10    /// Returns the provided nullable value if it is not <c>null</c>; otherwise, returns the specified default value or
 11    /// <see langword="default" /> for <typeparamref name="T" /> if no default is provided.
 12    /// </summary>
 13    /// <typeparam name="T">A value type.</typeparam>
 14    /// <param name="value">The nullable value to evaluate.</param>
 15    /// <param name="defaultValue">
 16    /// The value to return when <paramref name="value" /> is <c>null</c>. If omitted, <see langword="default" /> for
 17    /// <typeparamref name="T" /> is used.
 18    /// </param>
 19    /// <returns>
 20    /// The underlying value when <paramref name="value" /> has a value; otherwise, <paramref name="defaultValue" /> if
 21    /// provided, or <see langword="default" /> for <typeparamref name="T" />.
 22    /// </returns>
 23    public static T OrDefault<T>(this T? value, T defaultValue = default)
 24        where T : struct
 9225        => value ?? defaultValue;
 26}