< Summary

Information
Class: MyNet.Primitives.ConversionExtensions
Assembly: MyNet.Primitives
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Primitives/Conversion/Extensions/ConversionExtensions.cs
Tag: 323_28699572109
Line coverage
33%
Covered lines: 1
Uncovered lines: 2
Coverable lines: 3
Total lines: 52
Line coverage: 33.3%
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
To(...)100%11100%
To(...)100%210%
To(...)100%210%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ConversionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Runtime.CompilerServices;
 9using MyNet.Primitives.Conversion;
 10
 11#pragma warning disable IDE0130 // Namespace does not match folder structure
 12namespace MyNet.Primitives;
 13#pragma warning restore IDE0130 // Namespace does not match folder structure
 14
 15public static class ConversionExtensions
 16{
 17    extension(double value)
 18    {
 19        /// <summary>
 20        /// Converts the value from one unit to another using the registered unit converters.
 21        /// </summary>
 22        /// <param name="from">The unit of the input value.</param>
 23        /// <param name="to">The unit to convert the value to.</param>
 24        /// <typeparam name="TUnit">The type of the unit.</typeparam>
 25        /// <returns>The converted value.</returns>
 26        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 27        public double To<TUnit>(TUnit from, TUnit to)
 9928            where TUnit : struct, Enum => UnitConverterRegistry.Get<TUnit>().Convert(value, from, to);
 29
 30        /// <summary>
 31        /// Converts the value from its current unit to another unit using the registered unit converters. The current u
 32        /// </summary>
 33        /// <param name="to">The unit to convert the value to.</param>
 34        /// <typeparam name="TUnit">The type of the unit.</typeparam>
 35        /// <returns>The converted value.</returns>
 36        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 37        public double To<TUnit>(TUnit to)
 038            where TUnit : struct, Enum => value.To(default, to);
 39
 40        /// <summary>
 41        /// Converts the value from one unit to another using the registered unit converters. The type of the unit is de
 42        /// </summary>
 43        /// <param name="type">The type of the unit.</param>
 44        /// <param name="from">The unit of the input value.</param>
 45        /// <param name="to">The unit to convert the value to.</param>
 46        /// <returns>The converted value.</returns>
 47        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 48        public double To<TUnit>(Type type, TUnit from, TUnit to)
 049            where TUnit : struct, Enum => UnitConverterRegistry.Get<TUnit>(type).Convert(value, from, to);
 50    }
 51}
 52