Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is there a unit of measure that measures the general amount of something? #1524

Answered by lipchev
lkomanetz asked this question in Q&A
Discussion options

I work in the lumber processing industry and I've just started evaluating this library for our product. When a customer creates a list of what they need to produce they'll basically say

I want to produce pieces that are X wide and I want to produce Y amount of them.

For example, they want 20 board feet of 3.5 in. wide pieces. As they are creating this list they have one of three measurement options. The options are:

  • Board Feet
  • Linear Feet
  • Pieces

Does the library have an existing measurement that I can use so they can say "I want to produce five 3.5 in. pieces...I don't care how long the piece is or how much volume that piece has...I just want 5 of them." I started looking at creating a custom unit but became a bit overwhelmed and confused when trying to implement IQuantity<T>.

Right now I read the value from a data source in order to display the production requirements on the screen. What I wanted to do was to have two properties, RequiredUnits and UnitsProduced, that are defined as IQuantity so what I show on the screen could either be the string representation of Volume, Length, or this Amount measurement (if it exists). Any help or guidance would be greatly appreciated!

You must be logged in to vote

I think the closest thing to a "unit of something" would be the https://github.com/angularsen/UnitsNet/blob/master/Common/UnitDefinitions/Scalar.json.

However I'm not sure if this is really well suited for representing countable things (given the floaty-point nature of the IQuantity). You could map another unit abbreviation for it's unit, and using an integer-based format for the ToString etc, but I don't know..

I've personally used this type of definition OrderedAmount : OneOfBase<Volume, Mass, UnitaryQuantity> , where the last one is simply not an IQuantity (but usually comes with a unit such as pcs, as in "10 pcs").

Replies: 1 comment 1 reply

Comment options

I think the closest thing to a "unit of something" would be the https://github.com/angularsen/UnitsNet/blob/master/Common/UnitDefinitions/Scalar.json.

However I'm not sure if this is really well suited for representing countable things (given the floaty-point nature of the IQuantity). You could map another unit abbreviation for it's unit, and using an integer-based format for the ToString etc, but I don't know..

I've personally used this type of definition OrderedAmount : OneOfBase<Volume, Mass, UnitaryQuantity> , where the last one is simply not an IQuantity (but usually comes with a unit such as pcs, as in "10 pcs").

You must be logged in to vote
1 reply
Comment options

I see. So you have turned it into a discriminated union. Sometimes you see a solution and go, "why didn't I think of that?" This is one of those times. That makes a lot of sense because the amount could be OneOf<Volume, Length, Amount> with Amount just being a domain type that is metadata around what int represents. Thanks!

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

AltStyle によって変換されたページ (->オリジナル) /