Skip to content

Quantity from value and unit-abbreviation #1252

Answered by angularsen
igiona asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, sorry for the late reply.

If you are looking to serialize data to storage and read it back, I would recommend this instead:

IQuantity quantity = Quantity.From(value: 3, quantityName: "Length", unitName: "Centimeter");

if (Quantity.TryFrom(value: 3, quantityName: "Length", unitName: "Centimeter", out IQuantity? quantity2))
{
}

If you still need to store and read unit abbreviations, which I recommend against, then I just merged a naive feature for this you could try.
#1265

There is a relatively high chance of failure due to multiple units (across all quantities) having the same abbreviation.

New example in the README:

// Length with unit LengthUnit.Centimeter
IQuantity quantity = Quantity

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@igiona
Comment options

Answer selected by igiona
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants