BO4E.Extensions/ENUM/MengeneinheitExtension.cs
/// <summary>
///     returns the factor that is needed to convert an amount in unit <paramref name="me1" /> to an equivalent amount in
///     unit <paramref name="me2" />.
/// </summary>
/// <param name="me1">source unit</param>
/// <param name="me2">target unit</param>
/// <returns></returns>
/// <exception cref="InvalidOperationException">iff units do not have the same dimension</exception>
returns the factor that is needed to convert an amount in unit  to an equivalent amount in
unit .
returns the factor that is needed to convert an amount in unit to an equivalent amount in unit .
public static decimal GetConversionFactor(this Mengeneinheit me1, Mengeneinheit me2)
        {
#pragma warning disable 618
            if (me1 == Mengeneinheit.ZERO || me2 == Mengeneinheit.ZERO)
#pragma warning restore 618
                throw new InvalidOperationException("You must not use the artificial 'ZERO' value.");
            if (me1 == me2) return 1.0M;
            if (!me1.IsConvertibleTo(me2))
                throw new InvalidOperationException(
                    $"{me1} and {me2} are not convertible into each other because they don't share the same dimension.");
            if ((int)me1 % (int)me2 == 0 || (int)me2 % (int)me2 == 0) return (decimal)me1 / (decimal)me2;
            throw new InvalidOperationException($"{me1} and {me2} are not (trivially) convertible into each other.");
        }
public static decimal GetConversionFactor ( this Mengeneinheit me1 , Mengeneinheit me2 ) { pragma warning disable 618 if ( me1 == Mengeneinheit . ZERO || me2 == Mengeneinheit . ZERO ) pragma warning restore 618 throw new InvalidOperationException ( " " ) ; if ( me1 == me2 ) return 1.0M ; if ( ! me1 . IsConvertibleTo ( me2 ) ) throw new InvalidOperationException ( $" { me1 }  and  { me2 }  are not convertible into each other because they don't share the same dimension. " ) ; if ( ( int ) me1 % ( int ) me2 == 0 || ( int ) me2 % ( int ) me2 == 0 ) return ( decimal ) me1 / ( decimal ) me2 ; throw new InvalidOperationException ( $" { me1 }  and  { me2 }  are not (trivially) convertible into each other. " ) ; }
returns the factor that is needed to convert an amount in unit  to an equivalent amount in
unit .
returns the factor that is needed to convert an amount in unit to an equivalent amount in unit .
None
iff units do not have the same dimension
iff units do not have the same dimension
Mengeneinheit
this
me2
Mengeneinheit
None
me1
None