From 240b19d3ab11b9a63d5159207bc38018c11a78c1 Mon Sep 17 00:00:00 2001 From: Muximize Date: Mon, 26 Feb 2024 07:33:58 +0100 Subject: [PATCH] Implicit cast between Duration and TimeSpan (#1365) ### Changes - Change `Duration` from explicit to implicit cast to/from `TimeSpan` - Remove operator overloads for `TimeSpan` now covered by implicit cast for all but left operands ### Background See https://github.com/angularsen/UnitsNet/pull/1354#discussion_r1493344825 One issue is that the operator overloads only work when `TimeSpan` is the right operand. I changed the code generation to take this into account, but another option would be to make a breaking change where we just don't support `TimeSpan` as the left operand at all. Then users would have to cast explicitly, or for multiplication just reverse the operands. This would affect 13 operators: ``` TimeSpan * Acceleration TimeSpan * ElectricCurrent TimeSpan * ElectricCurrentGradient TimeSpan * ForceChangeRate TimeSpan * KinematicViscosity TimeSpan * MassFlow TimeSpan * MolarFlow TimeSpan * Power TimeSpan * PressureChangeRate TimeSpan * RotationalSpeed TimeSpan * Speed TimeSpan * TemperatureChangeRate TimeSpan * VolumeFlow ``` Of which only 6 are used in tests so I assume are supported in v5: ``` TimeSpan * KinematicViscosity TimeSpan * MassFlow TimeSpan * Power TimeSpan * RotationalSpeed TimeSpan * TemperatureChangeRate TimeSpan * Speed ``` --------- Co-authored-by: Andreas Gullberg Larsen --- CodeGen/Generators/QuantityRelationsParser.cs | 15 ++----------- .../UnitsNetGen/QuantityGenerator.cs | 10 --------- .../CustomCode/KinematicViscosityTests.cs | 7 ------ UnitsNet.Tests/CustomCode/MassFlowTests.cs | 7 ------ UnitsNet.Tests/CustomCode/PowerTests.cs | 7 ------ .../CustomCode/RotationalSpeedTests.cs | 7 ------ UnitsNet.Tests/CustomCode/SpeedTests.cs | 7 ------ .../CustomCode/TemperatureChangeRateTests.cs | 7 ------ .../CustomCode/Quantities/Duration.extra.cs | 22 ++++++++++++------- .../Quantities/Acceleration.g.cs | 20 ----------------- UnitsNet/GeneratedCode/Quantities/Angle.g.cs | 7 ------ .../Quantities/ElectricCharge.g.cs | 7 ------ .../Quantities/ElectricCurrent.g.cs | 20 ----------------- .../Quantities/ElectricCurrentGradient.g.cs | 13 ----------- UnitsNet/GeneratedCode/Quantities/Energy.g.cs | 7 ------ .../Quantities/ForceChangeRate.g.cs | 13 ----------- .../Quantities/KinematicViscosity.g.cs | 13 ----------- UnitsNet/GeneratedCode/Quantities/Length.g.cs | 7 ------ UnitsNet/GeneratedCode/Quantities/Mass.g.cs | 7 ------ .../GeneratedCode/Quantities/MassFlow.g.cs | 13 ----------- .../GeneratedCode/Quantities/MolarFlow.g.cs | 13 ----------- UnitsNet/GeneratedCode/Quantities/Power.g.cs | 13 ----------- .../GeneratedCode/Quantities/Pressure.g.cs | 7 ------ .../Quantities/PressureChangeRate.g.cs | 13 ----------- .../Quantities/RotationalSpeed.g.cs | 13 ----------- UnitsNet/GeneratedCode/Quantities/Speed.g.cs | 20 ----------------- .../Quantities/TemperatureChangeRate.g.cs | 13 ----------- UnitsNet/GeneratedCode/Quantities/Volume.g.cs | 7 ------ .../GeneratedCode/Quantities/VolumeFlow.g.cs | 13 ----------- 29 files changed, 16 insertions(+), 312 deletions(-) diff --git a/CodeGen/Generators/QuantityRelationsParser.cs b/CodeGen/Generators/QuantityRelationsParser.cs index 38f7abe5e8..9c28695af3 100644 --- a/CodeGen/Generators/QuantityRelationsParser.cs +++ b/CodeGen/Generators/QuantityRelationsParser.cs @@ -59,17 +59,6 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) }) .ToList()); - // We can infer TimeSpan relations from Duration relations. - var timeSpanQuantity = pseudoQuantity with { Name = "TimeSpan" }; - relations.AddRange(relations - .Where(r => r.LeftQuantity.Name is "Duration") - .Select(r => r with { LeftQuantity = timeSpanQuantity }) - .ToList()); - relations.AddRange(relations - .Where(r => r.RightQuantity.Name is "Duration") - .Select(r => r with { RightQuantity = timeSpanQuantity }) - .ToList()); - // Sort all relations to keep generated operators in a consistent order. relations.Sort(); @@ -96,9 +85,9 @@ public static void ParseAndApplyRelations(string rootDir, Quantity[] quantities) // The left operand of a relation is responsible for generating the operator. quantityRelations.Add(relation); } - else if (relation.RightQuantity == quantity && relation.LeftQuantity.Name is "double" or "TimeSpan") + else if (relation.RightQuantity == quantity && relation.LeftQuantity.Name is "double") { - // Because we cannot add generated operators to double or TimeSpan, we make the right operand responsible in this case. + // Because we cannot add operators to double we make the right operand responsible in this case. quantityRelations.Add(relation); } } diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index 5cfefa5370..f00adc0f88 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -746,16 +746,6 @@ private void GenerateRelationalOperators() var rightParameter = relation.RightQuantity.Name.ToCamelCase(); var rightConversionProperty = relation.RightUnit.PluralName; - if (relation.LeftQuantity.Name is nameof(TimeSpan)) - { - leftConversionProperty = "Total" + leftConversionProperty; - } - - if (relation.RightQuantity.Name is nameof(TimeSpan)) - { - rightConversionProperty = "Total" + rightConversionProperty; - } - if (leftParameter == rightParameter) { leftParameter = "left"; diff --git a/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs b/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs index d10e48c3a8..f1a487b86e 100644 --- a/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs +++ b/UnitsNet.Tests/CustomCode/KinematicViscosityTests.cs @@ -56,13 +56,6 @@ public static void KinematicViscosityTimesTimeSpanEqualsArea() Assert.Equal(area, Area.FromSquareMeters(8)); } - [Fact] - public static void TimeSpanTimesKinematicViscosityEqualsArea() - { - Area area = TimeSpan.FromSeconds(2)*KinematicViscosity.FromSquareMetersPerSecond(4); - Assert.Equal(area, Area.FromSquareMeters(8)); - } - [Fact] public static void KinematicViscosityTimesDensityEqualsDynamicViscosity() { diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs index 3c0ca9836b..19fe286228 100644 --- a/UnitsNet.Tests/CustomCode/MassFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -97,13 +97,6 @@ public void MassFlowTimesTimeSpanEqualsMass() Assert.Equal(mass, Mass.FromKilograms(80.0)); } - [Fact] - public void TimeSpanTimesMassFlowEqualsMass() - { - Mass mass = TimeSpan.FromSeconds(4.0) * MassFlow.FromKilogramsPerSecond(20.0); - Assert.Equal(mass, Mass.FromKilograms(80.0)); - } - [Fact] public void MassFlowDividedByBrakeSpecificFuelConsumptionEqualsPower() { diff --git a/UnitsNet.Tests/CustomCode/PowerTests.cs b/UnitsNet.Tests/CustomCode/PowerTests.cs index 1b80aad460..d55b2e2e21 100644 --- a/UnitsNet.Tests/CustomCode/PowerTests.cs +++ b/UnitsNet.Tests/CustomCode/PowerTests.cs @@ -104,13 +104,6 @@ public void PowerTimesTimeSpanEqualsEnergy() Assert.Equal(energy, Energy.FromJoules(40.0)); } - [Fact] - public void TimeSpanTimesPowerEqualsEnergy() - { - Energy energy = TimeSpan.FromSeconds(8.0) * Power.FromWatts(5.0); - Assert.Equal(energy, Energy.FromJoules(40.0)); - } - [Fact] public void PowerTimesBrakeSpecificFuelConsumptionEqualsMassFlow() { diff --git a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs index fcfb11b2db..e6be52c886 100644 --- a/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/RotationalSpeedTests.cs @@ -55,12 +55,5 @@ public void RotationalSpeedTimesTimeSpanEqualsAngle() Angle angle = RotationalSpeed.FromRadiansPerSecond(10.0)*TimeSpan.FromSeconds(9.0); Assert.Equal(angle, Angle.FromRadians(90.0)); } - - [Fact] - public void TimeSpanTimesRotationalSpeedEqualsAngle() - { - Angle angle = TimeSpan.FromSeconds(9.0)*RotationalSpeed.FromRadiansPerSecond(10.0); - Assert.Equal(angle, Angle.FromRadians(90.0)); - } } } diff --git a/UnitsNet.Tests/CustomCode/SpeedTests.cs b/UnitsNet.Tests/CustomCode/SpeedTests.cs index 629c61358e..068af70c58 100644 --- a/UnitsNet.Tests/CustomCode/SpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/SpeedTests.cs @@ -131,13 +131,6 @@ public void SpeedTimesTimeSpanEqualsLength() Assert.Equal(length, Length.FromMeters(40)); } - [Fact] - public void TimeSpanTimesSpeedEqualsLength() - { - Length length = TimeSpan.FromSeconds(2)*Speed.FromMetersPerSecond(20); - Assert.Equal(length, Length.FromMeters(40)); - } - [Fact] public void SpeedTimesLengthEqualsKinematicViscosity() { diff --git a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs index e4c0da0547..fe250c327b 100644 --- a/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs +++ b/UnitsNet.Tests/CustomCode/TemperatureChangeRateTests.cs @@ -36,13 +36,6 @@ public void TemperatureChangeRateMultipliedWithTimeSpanEqualsTemperatureDelta() Assert.Equal(TemperatureDelta.FromDegreesCelsius(20), d); } - [Fact] - public void TimeSpanMultipliedWithTemperatureChangeRateEqualsTemperatureDelta() - { - TemperatureDelta d = new TimeSpan(0, 0, -10) * TemperatureChangeRate.FromDegreesCelsiusPerSecond(2); - Assert.Equal(TemperatureDelta.FromDegreesCelsius(-20), d); - } - [Fact] public void TemperatureChangeRateMultipliedWithDurationEqualsTemperatureDelta() { diff --git a/UnitsNet/CustomCode/Quantities/Duration.extra.cs b/UnitsNet/CustomCode/Quantities/Duration.extra.cs index 4333d3c745..b72b51285a 100644 --- a/UnitsNet/CustomCode/Quantities/Duration.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Duration.extra.cs @@ -11,13 +11,19 @@ public partial struct Duration /// /// Convert a Duration to a TimeSpan. /// - /// Throws if the TimeSpan can't represent the Duration exactly + /// + /// Throws if the duration exceeds the . or + /// , which would cause it to roll over from positive to negative and vice versa. + /// /// The TimeSpan with the same time as the duration public TimeSpan ToTimeSpan() { - if ( Seconds > TimeSpan.MaxValue.TotalSeconds || - Seconds < TimeSpan.MinValue.TotalSeconds ) - throw new ArgumentOutOfRangeException( nameof( Duration ), "The duration is too large or small to fit in a TimeSpan" ); + if (Seconds > TimeSpan.MaxValue.TotalSeconds) throw new ArgumentOutOfRangeException(nameof(Seconds), + "The duration is too large for a TimeSpan, which would roll over from positive to negative."); + + if (Seconds < TimeSpan.MinValue.TotalSeconds) throw new ArgumentOutOfRangeException(nameof(Seconds), + "The duration is too small for a TimeSpan, which would roll over from negative to positive."); + return TimeSpan.FromTicks((long)(Seconds * TimeSpan.TicksPerSecond)); } @@ -33,14 +39,14 @@ public TimeSpan ToTimeSpan() return time.AddSeconds(-duration.Seconds); } - /// Explicitly cast to . - public static explicit operator TimeSpan(Duration duration) + /// Implicitly cast to . + public static implicit operator TimeSpan(Duration duration) { return duration.ToTimeSpan(); } - /// Explicitly cast to . - public static explicit operator Duration(TimeSpan duration) + /// Implicitly cast to . + public static implicit operator Duration(TimeSpan duration) { return FromSeconds(duration.TotalSeconds); } diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 79bc1d9af5..2dd67625dd 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -44,10 +44,8 @@ namespace UnitsNet #if NET7_0_OR_GREATER IMultiplyOperators, IDivisionOperators, - IDivisionOperators, IMultiplyOperators, IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -660,12 +658,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel return Jerk.FromMetersPerSecondCubed(acceleration.MetersPerSecondSquared / duration.Seconds); } - /// Get from / . - public static Jerk operator /(Acceleration acceleration, TimeSpan timeSpan) - { - return Jerk.FromMetersPerSecondCubed(acceleration.MetersPerSecondSquared / timeSpan.TotalSeconds); - } - /// Get from * . public static SpecificWeight operator *(Acceleration acceleration, Density density) { @@ -678,18 +670,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Accel return Speed.FromMetersPerSecond(acceleration.MetersPerSecondSquared * duration.Seconds); } - /// Get from * . - public static Speed operator *(Acceleration acceleration, TimeSpan timeSpan) - { - return Speed.FromMetersPerSecond(acceleration.MetersPerSecondSquared * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Speed operator *(TimeSpan timeSpan, Acceleration acceleration) - { - return Speed.FromMetersPerSecond(timeSpan.TotalSeconds * acceleration.MetersPerSecondSquared); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index e5c763b8a3..30e9c87f47 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IDivisionOperators, - IDivisionOperators, IMultiplyOperators, #endif IComparable, @@ -683,12 +682,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Angle return RotationalSpeed.FromRadiansPerSecond(angle.Radians / duration.Seconds); } - /// Get from / . - public static RotationalSpeed operator /(Angle angle, TimeSpan timeSpan) - { - return RotationalSpeed.FromRadiansPerSecond(angle.Radians / timeSpan.TotalSeconds); - } - /// Get from * . public static Torque operator *(Angle angle, RotationalStiffness rotationalStiffness) { diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index 7f4bff3a7d..5042285279 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -47,7 +47,6 @@ namespace UnitsNet #if NET7_0_OR_GREATER IDivisionOperators, IDivisionOperators, - IDivisionOperators, IMultiplyOperators, #endif IComparable, @@ -613,12 +612,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return ElectricCurrent.FromAmperes(electricCharge.AmpereHours / duration.Hours); } - /// Get from / . - public static ElectricCurrent operator /(ElectricCharge electricCharge, TimeSpan timeSpan) - { - return ElectricCurrent.FromAmperes(electricCharge.AmpereHours / timeSpan.TotalHours); - } - /// Get from * . public static Energy operator *(ElectricCharge electricCharge, ElectricPotential electricPotential) { diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 387cdf0626..9a5d304d76 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -43,9 +43,7 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, IDivisionOperators, - IDivisionOperators, IMultiplyOperators, IMultiplyOperators, #endif @@ -574,30 +572,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return ElectricCharge.FromAmpereHours(electricCurrent.Amperes * duration.Hours); } - /// Get from * . - public static ElectricCharge operator *(ElectricCurrent electricCurrent, TimeSpan timeSpan) - { - return ElectricCharge.FromAmpereHours(electricCurrent.Amperes * timeSpan.TotalHours); - } - - /// Get from * . - public static ElectricCharge operator *(TimeSpan timeSpan, ElectricCurrent electricCurrent) - { - return ElectricCharge.FromAmpereHours(timeSpan.TotalHours * electricCurrent.Amperes); - } - /// Get from / . public static ElectricCurrentGradient operator /(ElectricCurrent electricCurrent, Duration duration) { return ElectricCurrentGradient.FromAmperesPerSecond(electricCurrent.Amperes / duration.Seconds); } - /// Get from / . - public static ElectricCurrentGradient operator /(ElectricCurrent electricCurrent, TimeSpan timeSpan) - { - return ElectricCurrentGradient.FromAmperesPerSecond(electricCurrent.Amperes / timeSpan.TotalSeconds); - } - /// Get from * . public static ElectricPotential operator *(ElectricCurrent electricCurrent, ElectricResistance electricResistance) { diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index c7da409281..9e4a93f316 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -538,18 +537,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Elect return ElectricCurrent.FromAmperes(electricCurrentGradient.AmperesPerSecond * duration.Seconds); } - /// Get from * . - public static ElectricCurrent operator *(ElectricCurrentGradient electricCurrentGradient, TimeSpan timeSpan) - { - return ElectricCurrent.FromAmperes(electricCurrentGradient.AmperesPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static ElectricCurrent operator *(TimeSpan timeSpan, ElectricCurrentGradient electricCurrentGradient) - { - return ElectricCurrent.FromAmperes(timeSpan.TotalSeconds * electricCurrentGradient.AmperesPerSecond); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index 010cdd2be9..3710d9f452 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -49,7 +49,6 @@ namespace UnitsNet IDivisionOperators, IMultiplyOperators, IDivisionOperators, - IDivisionOperators, IDivisionOperators, IDivisionOperators, #endif @@ -1110,12 +1109,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Energ return Power.FromWatts(energy.Joules / duration.Seconds); } - /// Get from / . - public static Power operator /(Energy energy, TimeSpan timeSpan) - { - return Power.FromWatts(energy.Joules / timeSpan.TotalSeconds); - } - /// Get from / . public static SpecificEnergy operator /(Energy energy, Mass mass) { diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index ee270ec3a0..8593920393 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -666,18 +665,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Force return Force.FromNewtons(forceChangeRate.NewtonsPerSecond * duration.Seconds); } - /// Get from * . - public static Force operator *(ForceChangeRate forceChangeRate, TimeSpan timeSpan) - { - return Force.FromNewtons(forceChangeRate.NewtonsPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Force operator *(TimeSpan timeSpan, ForceChangeRate forceChangeRate) - { - return Force.FromNewtons(timeSpan.TotalSeconds * forceChangeRate.NewtonsPerSecond); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index 4276bcde9e..e8fe56ad67 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -46,7 +46,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, IMultiplyOperators, IDivisionOperators, #endif @@ -575,18 +574,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Kinem return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * duration.Seconds); } - /// Get from * . - public static Area operator *(KinematicViscosity kinematicViscosity, TimeSpan timeSpan) - { - return Area.FromSquareMeters(kinematicViscosity.SquareMetersPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Area operator *(TimeSpan timeSpan, KinematicViscosity kinematicViscosity) - { - return Area.FromSquareMeters(timeSpan.TotalSeconds * kinematicViscosity.SquareMetersPerSecond); - } - /// Get from * . public static DynamicViscosity operator *(KinematicViscosity kinematicViscosity, Density density) { diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 13fa343521..e6695b1d5b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -50,7 +50,6 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IDivisionOperators, - IDivisionOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, @@ -1157,12 +1156,6 @@ public ReciprocalLength Inverse() return Speed.FromMetersPerSecond(length.Meters / duration.Seconds); } - /// Get from / . - public static Speed operator /(Length length, TimeSpan timeSpan) - { - return Speed.FromMetersPerSecond(length.Meters / timeSpan.TotalSeconds); - } - /// Get from * . public static TemperatureDelta operator *(Length length, TemperatureGradient temperatureGradient) { diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index cbdae2e60c..fbb52246e6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -54,7 +54,6 @@ namespace UnitsNet IMultiplyOperators, IDivisionOperators, IDivisionOperators, - IDivisionOperators, IMultiplyOperators, IDivisionOperators, #endif @@ -937,12 +936,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassU return MassFlow.FromKilogramsPerSecond(mass.Kilograms / duration.Seconds); } - /// Get from / . - public static MassFlow operator /(Mass mass, TimeSpan timeSpan) - { - return MassFlow.FromKilogramsPerSecond(mass.Kilograms / timeSpan.TotalSeconds); - } - /// Get from * . public static Volume operator *(Mass mass, SpecificVolume specificVolume) { diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 45a03749d8..2dc2d81e6c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -46,7 +46,6 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IMultiplyOperators, - IMultiplyOperators, IDivisionOperators, IMultiplyOperators, IDivisionOperators, @@ -979,18 +978,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out MassF return Mass.FromKilograms(massFlow.KilogramsPerSecond * duration.Seconds); } - /// Get from * . - public static Mass operator *(MassFlow massFlow, TimeSpan timeSpan) - { - return Mass.FromKilograms(massFlow.KilogramsPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Mass operator *(TimeSpan timeSpan, MassFlow massFlow) - { - return Mass.FromKilograms(timeSpan.TotalSeconds * massFlow.KilogramsPerSecond); - } - /// Get from / . public static MassFlux operator /(MassFlow massFlow, Area area) { diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index 5919e4195d..fdd3530417 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, IMultiplyOperators, IDivisionOperators, #endif @@ -572,18 +571,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Molar return AmountOfSubstance.FromKilomoles(molarFlow.KilomolesPerSecond * duration.Seconds); } - /// Get from * . - public static AmountOfSubstance operator *(MolarFlow molarFlow, TimeSpan timeSpan) - { - return AmountOfSubstance.FromKilomoles(molarFlow.KilomolesPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static AmountOfSubstance operator *(TimeSpan timeSpan, MolarFlow molarFlow) - { - return AmountOfSubstance.FromKilomoles(timeSpan.TotalSeconds * molarFlow.KilomolesPerSecond); - } - /// Get from * . public static MassFlow operator *(MolarFlow molarFlow, MolarMass molarMass) { diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index 1c635333bb..3514c7be25 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -46,7 +46,6 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IMultiplyOperators, - IMultiplyOperators, IDivisionOperators, IDivisionOperators, IMultiplyOperators, @@ -870,18 +869,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Power return Energy.FromJoules(power.Watts * duration.Seconds); } - /// Get from * . - public static Energy operator *(Power power, TimeSpan timeSpan) - { - return Energy.FromJoules(power.Watts * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Energy operator *(TimeSpan timeSpan, Power power) - { - return Energy.FromJoules(timeSpan.TotalSeconds * power.Watts); - } - /// Get from / . public static Force operator /(Power power, Speed speed) { diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index 001af7956c..461320f9ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -47,7 +47,6 @@ namespace UnitsNet IDivisionOperators, IDivisionOperators, IDivisionOperators, - IDivisionOperators, IDivisionOperators, #endif IComparable, @@ -1239,12 +1238,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press return PressureChangeRate.FromPascalsPerSecond(pressure.Pascals / duration.Seconds); } - /// Get from / . - public static PressureChangeRate operator /(Pressure pressure, TimeSpan timeSpan) - { - return PressureChangeRate.FromPascalsPerSecond(pressure.Pascals / timeSpan.TotalSeconds); - } - /// Get from / . public static SpecificWeight operator /(Pressure pressure, Length length) { diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index 0536d80c9d..79c0e35242 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -714,18 +713,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Press return Pressure.FromPascals(pressureChangeRate.PascalsPerSecond * duration.Seconds); } - /// Get from * . - public static Pressure operator *(PressureChangeRate pressureChangeRate, TimeSpan timeSpan) - { - return Pressure.FromPascals(pressureChangeRate.PascalsPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Pressure operator *(TimeSpan timeSpan, PressureChangeRate pressureChangeRate) - { - return Pressure.FromPascals(timeSpan.TotalSeconds * pressureChangeRate.PascalsPerSecond); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index 4d0bd4f8f7..72a953fa87 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -634,18 +633,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Rotat return Angle.FromRadians(rotationalSpeed.RadiansPerSecond * duration.Seconds); } - /// Get from * . - public static Angle operator *(RotationalSpeed rotationalSpeed, TimeSpan timeSpan) - { - return Angle.FromRadians(rotationalSpeed.RadiansPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Angle operator *(TimeSpan timeSpan, RotationalSpeed rotationalSpeed) - { - return Angle.FromRadians(timeSpan.TotalSeconds * rotationalSpeed.RadiansPerSecond); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index b44de3132c..9b5a9a80e6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -43,11 +43,9 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IDivisionOperators, - IDivisionOperators, IDivisionOperators, IMultiplyOperators, IMultiplyOperators, - IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, IMultiplyOperators, @@ -962,12 +960,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speed return Acceleration.FromMetersPerSecondSquared(speed.MetersPerSecond / duration.Seconds); } - /// Get from / . - public static Acceleration operator /(Speed speed, TimeSpan timeSpan) - { - return Acceleration.FromMetersPerSecondSquared(speed.MetersPerSecond / timeSpan.TotalSeconds); - } - /// Get from / . public static Duration operator /(Speed speed, Acceleration acceleration) { @@ -986,18 +978,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Speed return Length.FromMeters(speed.MetersPerSecond * duration.Seconds); } - /// Get from * . - public static Length operator *(Speed speed, TimeSpan timeSpan) - { - return Length.FromMeters(speed.MetersPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static Length operator *(TimeSpan timeSpan, Speed speed) - { - return Length.FromMeters(timeSpan.TotalSeconds * speed.MetersPerSecond); - } - /// Get from * . public static MassFlux operator *(Speed speed, Density density) { diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index a6f0d721f1..b801bea101 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -43,7 +43,6 @@ namespace UnitsNet IArithmeticQuantity, #if NET7_0_OR_GREATER IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -586,18 +585,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Tempe return TemperatureDelta.FromDegreesCelsius(temperatureChangeRate.DegreesCelsiusPerSecond * duration.Seconds); } - /// Get from * . - public static TemperatureDelta operator *(TemperatureChangeRate temperatureChangeRate, TimeSpan timeSpan) - { - return TemperatureDelta.FromDegreesCelsius(temperatureChangeRate.DegreesCelsiusPerSecond * timeSpan.TotalSeconds); - } - - /// Get from * . - public static TemperatureDelta operator *(TimeSpan timeSpan, TemperatureChangeRate temperatureChangeRate) - { - return TemperatureDelta.FromDegreesCelsius(timeSpan.TotalSeconds * temperatureChangeRate.DegreesCelsiusPerSecond); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index db6de26d11..1f7613d346 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -48,7 +48,6 @@ namespace UnitsNet IMultiplyOperators, IMultiplyOperators, IDivisionOperators, - IDivisionOperators, #endif IComparable, IComparable, @@ -1325,12 +1324,6 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return VolumeFlow.FromCubicMetersPerSecond(volume.CubicMeters / duration.Seconds); } - /// Get from / . - public static VolumeFlow operator /(Volume volume, TimeSpan timeSpan) - { - return VolumeFlow.FromCubicMetersPerSecond(volume.CubicMeters / timeSpan.TotalSeconds); - } - #endregion #region Equality / IComparable diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index ae92dbd033..bf86afcf8b 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -46,7 +46,6 @@ namespace UnitsNet IMultiplyOperators, IDivisionOperators, IMultiplyOperators, - IMultiplyOperators, #endif IComparable, IComparable, @@ -1513,24 +1512,12 @@ public static bool TryParseUnit(string str, IFormatProvider? provider, out Volum return Speed.FromMetersPerSecond(volumeFlow.CubicMetersPerSecond / area.SquareMeters); } - /// Get from * . - public static Volume operator *(TimeSpan timeSpan, VolumeFlow volumeFlow) - { - return Volume.FromCubicMeters(timeSpan.TotalSeconds * volumeFlow.CubicMetersPerSecond); - } - /// Get from * . public static Volume operator *(VolumeFlow volumeFlow, Duration duration) { return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * duration.Seconds); } - /// Get from * . - public static Volume operator *(VolumeFlow volumeFlow, TimeSpan timeSpan) - { - return Volume.FromCubicMeters(volumeFlow.CubicMetersPerSecond * timeSpan.TotalSeconds); - } - #endregion #region Equality / IComparable