Replies: 9 comments 35 replies
-
Clever idea, although it does feel a bit complicated at first glance. My initial thinking is that we might be better off letting the user choose a numeric type across the board, similar to Math.NET matrices, but I do see the benefit of allowing any numeric type and giving the option to control overflows/infinity. I'll let the idea mature a bit in my head. |
Beta Was this translation helpful? Give feedback.
-
CC @tmilnthorp |
Beta Was this translation helpful? Give feedback.
-
I had thought of something similar, albeit constructing with an I don't think this is a bad strategy. Does it have any pros/cons over switching to generics at some point? |
Beta Was this translation helpful? Give feedback.
-
This was also independently raised here: #1048
The best argument I could think of against might be serialization, but perhaps if we stick with double/decimal and not I think I don't see generics happening anytime soon. I think it's a huge breaking change to go from value types to reference types and also I think value types is the better choice. We could keep Information oneByte1 = Information.FromBytes(1);
IQuantity oneByte2 = (IQuantity)oneByte1;
var bytes1 = oneByte1.Value; // decimal
var bytes2 = oneByte2.Value; // QuantityValue |
Beta Was this translation helpful? Give feedback.
-
Generics don’t require reference types btw |
Beta Was this translation helpful? Give feedback.
-
One (big) problem was how to make them work as single nuget, or alternatively how to make the two nugets work with one another. |
Beta Was this translation helpful? Give feedback.
-
I think a key point that we should probably also have a discussion about is what would be the ideal internal representation of the value field. Should it be double/decimal, QuantityValue or even maybe something fancier like Fractions? |
Beta Was this translation helpful? Give feedback.
-
For visibility, I am re-posting this: #875 (reply in thread) Although generic value types seems nice to have, it is likely that only a minority will make use of it and it adds a lot of complexity to our code base. The mission of Units.NET has from the start been to simplify things for most users, not to cover every use case. ProposalImplement solution A -
|
Beta Was this translation helpful? Give feedback.
-
Regarding solution A: Taking advantage of the fact that Small prototype with only rudimentary operator support and handling of different underlying types:
Size comparison
|
Beta Was this translation helpful? Give feedback.
-
I think we've largely covered the generics route for doing this in #714.
But have you considered boxing the Quantity.Value with something like the QuantityValue that is used in the constructor? It seems to me that we'd only need to implement IConvertible, add a few operators like
QuantityValue + QuantityValue, QuantityValue + double, QuantityValue + decimal
and possibly some constructor supplied strategy for determining the resulting type of a mixed type operation.Example usage:
I'm not yet sure what the TypeStrategy (or whatever the name might be) would have as options but something along the lines of:
Beta Was this translation helpful? Give feedback.
All reactions