-
Notifications
You must be signed in to change notification settings - Fork 404
-
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!
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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").
Beta Was this translation helpful? Give feedback.
All reactions
-
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!
Beta Was this translation helpful? Give feedback.