Repository navigation
[v5] Convert quantities to and from a UnitOf<TQuantity> - #1739
Open
tmilnthorp wants to merge 1 commit into
Open
tmilnthorp wants to merge 1 commit into
tmilnthorp wants to merge 1 commit into
Conversation
UnitOf<TQuantity> describes a unit of a quantity by its names and its value in the base unit of the quantity, without a unit enum value. Quantities can be converted to it with As(UnitOf<TQuantity>), and created from a value in it with QuantityInfo.From(value, UnitOf<TQuantity>), which returns the quantity in its base unit. This is the subset of the v6 API that v5 supports, so code written against it keeps compiling on v6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG
This was referenced Oct 6, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of the forward-compatible part of #1738 to v5. It adds
UnitOf<TQuantity>, a unit of a quantity described by its names and its value in the base unit, without a unit enum value. Quantities can be converted to and from such a unit with no setup.UnitOf<TQuantity>optionally takes the base units it's made of, e.g. feet per day:new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Day).quantity.As(UnitOf<TQuantity>)returns the value in that unit. Using a unit of another quantity doesn't compile.quantityInfo.From(value, UnitOf<TQuantity>)returns the quantity in its base unit. It throwsArgumentExceptionfor the info of another quantity.Purely additive, and the same call sites compile on v6, so code written against this keeps working after upgrading. v6 builds further on it:
IUnitDefinition;From;Related: #1738, #1246, #1562
🤖 Generated with Claude Code
https://claude.ai/code/session_012XKhDsyHDc5BHrmibxScqG