@@ -60,44 +60,59 @@ public void ToUnit_UnitSystem_ThrowsArgumentNullExceptionIfNull()
6060 }
6161
6262 [ Fact ]
63- public void UnitInfo_ReturnsUnitInfoForQuantityUnit ( )
63+ public void GetUnitInfo_ReturnsUnitInfoForQuantityUnit ( )
6464 {
6565 var length = new Length ( 3.0 , LengthUnit . Centimeter ) ;
6666 IQuantity quantity = length ;
6767
68- UnitInfo unitInfo = quantity . UnitInfo ;
68+ UnitInfo unitInfo = quantity . GetUnitInfo ( ) ;
6969
7070 Assert . Equal ( nameof ( LengthUnit . Centimeter ) , unitInfo . Name ) ;
7171 Assert . Equal ( quantity . UnitKey , unitInfo . UnitKey ) ;
7272 }
7373
7474 [ Fact ]
75- public void UnitInfo_Zero_ReturnsBaseUnitInfo ( )
75+ public void GetUnitInfo_Zero_ReturnsBaseUnitInfo ( )
7676 {
7777 IQuantity quantity = Length . Info . Zero ;
7878
79- UnitInfo unitInfo = quantity . UnitInfo ;
79+ UnitInfo unitInfo = quantity . GetUnitInfo ( ) ;
8080
8181 Assert . Equal ( Length . Info . BaseUnitInfo . UnitKey , unitInfo . UnitKey ) ;
8282 }
8383
8484 [ Fact ]
85- public void UnitInfo_TypedQuantity_ReturnsTypedUnitInfo ( )
85+ public void GetUnitInfo_ConcreteQuantity_ReturnsFullyTypedUnitInfo ( )
8686 {
87- IQuantity < LengthUnit > quantity = new Length ( 3.0 , LengthUnit . Centimeter ) ;
87+ var quantity = new Length ( 3.0 , LengthUnit . Centimeter ) ;
8888
89- UnitInfo < LengthUnit > unitInfo = quantity . UnitInfo ;
89+ // Overload resolution picks GetUnitInfo<TQuantity, TUnit> for the concrete struct receiver,
90+ // returning the most specific UnitInfo<Length, LengthUnit>.
91+ UnitInfo < Length , LengthUnit > unitInfo = quantity . GetUnitInfo ( ) ;
9092
9193 Assert . Equal ( LengthUnit . Centimeter , unitInfo . Value ) ;
9294 Assert . Equal ( nameof ( LengthUnit . Centimeter ) , unitInfo . Name ) ;
9395 }
9496
9597 [ Fact ]
96- public void UnitInfo_MatchesUnit ( )
98+ public void GetUnitInfo_TypedQuantityReference_FallsBackToNonGeneric ( )
99+ {
100+ IQuantity < LengthUnit > quantity = new Length ( 3.0 , LengthUnit . Centimeter ) ;
101+
102+ // The IQuantity<TUnit> reference does not satisfy the IQuantity<TSelf, TUnit> constraint
103+ // (TSelf would be IQuantity<MassUnit>), so resolution falls back to GetUnitInfo(IQuantity).
104+ UnitInfo unitInfo = quantity . GetUnitInfo ( ) ;
105+
106+ Assert . Equal ( LengthUnit . Centimeter , ( ( UnitInfo < LengthUnit > ) unitInfo ) . Value ) ;
107+ Assert . Equal ( nameof ( LengthUnit . Centimeter ) , unitInfo . Name ) ;
108+ }
109+
110+ [ Fact ]
111+ public void GetUnitInfo_MatchesUnit ( )
97112 {
98113 Assert . All ( Quantity . Infos . Select ( x => x . Zero ) , quantity =>
99114 {
100- Assert . Equal ( quantity . Unit , quantity . UnitInfo . Value ) ;
115+ Assert . Equal ( quantity . Unit , quantity . GetUnitInfo ( ) . Value ) ;
101116 } ) ;
102117 }
103118
0 commit comments