@@ -8,16 +8,18 @@ namespace UnitsNet.Tests.CustomQuantities
8
8
/// </summary>
9
9
public struct HowMuch : IQuantity
10
10
{
11
- public HowMuch ( double value , Enum unit ) : this ( )
11
+ public HowMuch ( double value , HowMuchUnit unit )
12
12
{
13
13
Unit = unit ;
14
14
Value = value ;
15
15
}
16
16
17
- public Enum Unit { get ; }
17
+ Enum IQuantity . Unit => Unit ;
18
+ public HowMuchUnit Unit { get ; }
19
+
18
20
public double Value { get ; }
19
21
20
- #region Crud to satisfy IQuantity, but not really used for anything
22
+ #region IQuantity
21
23
22
24
private static readonly HowMuch Zero = new HowMuch ( 0 , HowMuchUnit . Some ) ;
23
25
@@ -39,10 +41,15 @@ public HowMuch(double value, Enum unit) : this()
39
41
40
42
public double As ( UnitSystem unitSystem ) => throw new NotImplementedException ( ) ;
41
43
42
- public IQuantity ToUnit ( Enum unit ) => new HowMuch ( As ( unit ) , unit ) ;
44
+ public IQuantity ToUnit ( Enum unit )
45
+ {
46
+ if ( unit is HowMuchUnit howMuchUnit ) return new HowMuch ( As ( unit ) , howMuchUnit ) ;
47
+ throw new ArgumentException ( "Must be of type HowMuchUnit." , nameof ( unit ) ) ;
48
+ }
43
49
44
50
public IQuantity ToUnit ( UnitSystem unitSystem ) => throw new NotImplementedException ( ) ;
45
51
52
+ public override string ToString ( ) => $ "{ Value } { Unit } ";
46
53
public string ToString ( string format , IFormatProvider formatProvider ) => $ "HowMuch ({ format } , { formatProvider } )";
47
54
public string ToString ( IFormatProvider provider ) => $ "HowMuch ({ provider } )";
48
55
public string ToString ( IFormatProvider provider , int significantDigitsAfterRadix ) => $ "HowMuch ({ provider } , { significantDigitsAfterRadix } )";
0 commit comments