File tree 5 files changed +23
-7
lines changed
UnitsNet/CustomCode/Quantities
UnitsNet.Tests/CustomCode
5 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ public static void ComponentMassFromMassConcentrationAndSolutionVolume(
131
131
var massConcentration = new MassConcentration ( massConcValue , massConcUnit ) ;
132
132
var volume = new Volume ( volumeValue , volumeUnit ) ;
133
133
134
- Mass massComponent = massConcentration * volume ;
134
+ Mass massComponent = ( Density ) massConcentration * volume ;
135
135
136
136
AssertEx . EqualTolerance ( expectedMassValue , massComponent . As ( expectedMassUnit ) , tolerance ) ;
137
137
}
Original file line number Diff line number Diff line change @@ -5,13 +5,29 @@ namespace UnitsNet
5
5
{
6
6
public partial struct MassConcentration
7
7
{
8
+ /// <summary>
9
+ /// Because Density and MassConcentration are almost the same, we can convert between them.
10
+ /// </summary>
11
+ public static implicit operator MassConcentration ( Density density )
12
+ {
13
+ return From ( density . ToUnit ( Density . BaseUnit ) . Value , BaseUnit ) ;
14
+ }
15
+
16
+ /// <summary>
17
+ /// Because Density and MassConcentration are almost the same, we can convert between them.
18
+ /// </summary>
19
+ public static explicit operator Density ( MassConcentration massConcentration )
20
+ {
21
+ return Density . From ( massConcentration . ToUnit ( BaseUnit ) . Value , Density . BaseUnit ) ;
22
+ }
23
+
8
24
/// <summary>
9
25
/// Get <see cref="Molarity" /> from this <see cref="MassConcentration" /> using the known component <see cref="MolarMass" />.
10
26
/// </summary>
11
27
/// <param name="molecularWeight"></param>
12
28
public Molarity ToMolarity ( MolarMass molecularWeight )
13
29
{
14
- return this / molecularWeight ;
30
+ return ( Density ) this / molecularWeight ;
15
31
}
16
32
17
33
/// <summary>
@@ -21,7 +37,7 @@ public Molarity ToMolarity(MolarMass molecularWeight)
21
37
/// <returns></returns>
22
38
public VolumeConcentration ToVolumeConcentration ( Density componentDensity )
23
39
{
24
- return this / componentDensity ;
40
+ return VolumeConcentration . FromDecimalFractions ( ( Density ) this / componentDensity ) ;
25
41
}
26
42
27
43
#region Static Methods
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ public partial struct MassFraction
11
11
/// <returns>The actual mass of the component involved in this mixture</returns>
12
12
public Mass GetComponentMass ( Mass totalMass )
13
13
{
14
- return totalMass * this ;
14
+ return totalMass * DecimalFractions ;
15
15
}
16
16
17
17
/// <summary>
@@ -21,7 +21,7 @@ public Mass GetComponentMass(Mass totalMass)
21
21
/// <returns>The total mass of the mixture</returns>
22
22
public Mass GetTotalMass ( Mass componentMass )
23
23
{
24
- return componentMass / this ;
24
+ return componentMass / DecimalFractions ;
25
25
}
26
26
27
27
#region Static Methods
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ public MassConcentration ToMassConcentration(MolarMass molecularWeight)
20
20
/// <param name="componentMass"></param>
21
21
public VolumeConcentration ToVolumeConcentration ( Density componentDensity , MolarMass componentMass )
22
22
{
23
- return this * componentMass / componentDensity ;
23
+ return VolumeConcentration . FromDecimalFractions ( this * componentMass / componentDensity ) ;
24
24
}
25
25
26
26
#region Static Methods
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ public static VolumeConcentration FromVolumes(Volume componentVolume, Volume mix
43
43
/// <param name="componentMolarMass"></param>
44
44
public static VolumeConcentration FromMolarity ( Molarity molarity , Density componentDensity , MolarMass componentMolarMass )
45
45
{
46
- return molarity * componentMolarMass / componentDensity ;
46
+ return FromDecimalFractions ( molarity * componentMolarMass / componentDensity ) ;
47
47
}
48
48
49
49
#endregion
You can’t perform that action at this time.
0 commit comments