< Summary

Information
Class: MyNet.Primitives.BooleanExtensions
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Extensions/BooleanExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IfTrue(...)100%22100%
IfFalse(...)100%22100%
IsTrue(...)100%11100%
IsFalse(...)100%11100%
IfTrue(...)100%22100%
IfFalse(...)100%22100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Extensions/BooleanExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="BooleanExtensions.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
 13public static class BooleanExtensions
 14{
 15    extension(bool value)
 16    {
 17        /// <summary>
 18        /// Executes the specified action if the boolean is true. If the boolean is false, the action is not executed.
 19        /// </summary>
 20        /// <param name="ifTrue">The action to execute if the boolean is true.</param>
 21        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="ifTrue"/> action is null.</exception>
 22        public void IfTrue(Action ifTrue)
 23        {
 1224            ArgumentNullException.ThrowIfNull(ifTrue);
 25
 926            if (value)
 627                ifTrue();
 928        }
 29
 30        /// <summary>
 31        /// Executes the specified action if the boolean is false. If the boolean is true, the action is not executed.
 32        /// </summary>
 33        /// <param name="ifFalse">The action to execute if the boolean is false.</param>
 34        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="ifFalse"/> action is null.</exception>
 35        public void IfFalse(Action ifFalse)
 36        {
 5137            ArgumentNullException.ThrowIfNull(ifFalse);
 38
 4839            if (!value)
 4540                ifFalse();
 4841        }
 42    }
 43
 44    extension(bool? value)
 45    {
 46        /// <summary>
 47        /// Returns true if the nullable boolean has a value of true; otherwise, false. This method returns false if the
 48        /// </summary>
 1849        public bool IsTrue() => value == true;
 50
 51        /// <summary>
 52        /// Returns true if the nullable boolean has a value of false; otherwise, false. This method returns false if th
 53        /// </summary>
 1854        public bool IsFalse() => value != true;
 55
 56        /// <summary>
 57        /// Executes the specified action if the nullable boolean has a value of true. If the nullable boolean is null o
 58        /// </summary>
 59        /// <param name="ifTrue">The action to execute if the nullable boolean is true.</param>
 60        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="ifTrue"/> action is null.</exception>
 61        public void IfTrue(Action ifTrue)
 62        {
 1263            ArgumentNullException.ThrowIfNull(ifTrue);
 64
 965            if (value.IsTrue())
 366                ifTrue();
 967        }
 68
 69        /// <summary>
 70        /// Executes the specified action if the nullable boolean has a value of false. If the nullable boolean is null 
 71        /// </summary>
 72        /// <param name="ifFalse">The action to execute if the nullable boolean is false.</param>
 73        /// <exception cref="ArgumentNullException">Thrown if the <paramref name="ifFalse"/> action is null.</exception>
 74        public void IfFalse(Action ifFalse)
 75        {
 1276            ArgumentNullException.ThrowIfNull(ifFalse);
 77
 978            if (value.IsFalse())
 679                ifFalse();
 980        }
 81    }
 82}
 83