Question

I would like to be able to do such things as

var m1 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Pounds);
var m2 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Liters);

m1.ToKilograms();
m2.ToPounds(new Density(7.0, DensityType.PoundsPerGallon);

If there isn't something like this already, anybody interested in doing it as an os project?

Was it helpful?

Solution

Check out the Measurement Unit Conversion Library on The Code Project.

OTHER TIPS

We actually built one in-house where I work. Unfortunately, it's not available for the public.

This is actually a great project to work on and it's not that hard to do. If you plan on doing something by yourself, I suggest you read about Quantity, Dimension and Unit (fundamental units).

These helped us understand the domain of the problem clearly and helped a lot in designing the library.

In Chapter 10. Quantity archetype pattern of the book Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML by Jim Arlow and Ila Neustadt there is a really useful discussion of this topic and some general patterns you could use as a guide.

Also see the most recent F# release - it has static measurement domain/dimension analysis.

There is an (old) article on CodeProject. I've used it in a production environment previously and it worked great. We had some minor issues (performance amongst others), which I addressed. I put all this in a library you can find here.

Disclaimer: I am the maintainer of this project, so this might be conceived as a shameless plug. The library is free (as in beer and as in speech) however.

It includes the SI units, but also allows creating new units and conversions.

So you can for example create a unit "XP" (experience points). You can then register a conversion to "m" (meter, makes no sense, but you can do it). You can also create an amount like 3 XP/min (3 experience points per minute). I believe it offers decent defaults, while allowing flexibility.

Unix units is imho brilliant; source must be on the web somewhere.
(Under "bugs", the original doc said "do not base your financial plans on the currency conversions".)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top