Skip to content

Commit a959971

Browse files
angularsenclaude
andcommitted
Fix CS0266 in GetUnitInfo<TQuantity,TUnit> typed overload
The Azure Pipelines build of #1657 (master) fails with: error CS0266: Cannot implicitly convert type 'UnitInfo<TUnit>' to 'UnitInfo<TQuantity, TUnit>' at: return quantity.QuantityInfo[quantity.Unit]; The receiver is statically IQuantity<TQuantity, TUnit>, whose QuantityInfo getter is shadowed (`new`) to return the more specific QuantityInfo<TQuantity, TUnit>. Roslyn's member lookup on hosted images resolves the inherited IQuantity<TUnit>.QuantityInfo (QuantityInfo<TUnit>) instead, so the indexer returns UnitInfo<TUnit> and the conversion to UnitInfo<TQuantity, TUnit> fails. The runtime value is always the more derived type, so cast through QuantityInfo<TQuantity, TUnit> explicitly to surface the typed indexer. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 700617d commit a959971

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

UnitsNet/Extensions/QuantityExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public static UnitInfo<TQuantity, TUnit> GetUnitInfo<TQuantity, TUnit>(this IQua
4444
where TQuantity : IQuantity<TQuantity, TUnit>
4545
where TUnit : struct, Enum
4646
{
47-
return quantity.QuantityInfo[quantity.Unit];
47+
// Azure CI build failed on binding QuantityInfo through IQuantity<TUnit>, so cast to expose the fully typed indexer.
48+
// This is likely a .NET SDK version compatibility thing, did not bother looking closer at it.
49+
var quantityInfo = (QuantityInfo<TQuantity, TUnit>)quantity.QuantityInfo;
50+
return quantityInfo[quantity.Unit];
4851
}
4952

5053
/// <inheritdoc cref="IQuantity.As(UnitKey)" />

0 commit comments

Comments
 (0)