Converter.Temperature This project was created to extract out the main conversion code from the Temperature Converter applications in the other repositories. I am using this as a way to show how my development skills have changed over the years, as I get to be a better developer.
These extension methods will convert different types of temperatures to other types.
This library is built using the following tech stacks.
The project is a Visual Studio solution (.sln
).
There are more details on the project wiki.
The details contained on the wiki are more comprehensive. This document is to show you how I decided the library should be consumed.
To start with, I had a few ideas on how to do the extension methods but decided on using a fluent style. This is a common style used in development. I also think it looks nicer.
Originally, the extensions looked like this:
var tempToConvert = 34; // an int.
var convertedTemp = tempToConvert.CelsiusToFahrenheit();
Then I thought that this looked a bit naf so, I went with setting up the from first, then the to. This follows the fluent pattern.
Now it is used like this:
var tempToConvert = 34; // an int.
var convertedTemp = tempToConvert.FromCelsius().ToFahrenheit();
For version 2 I added an additional usage like this:
var tempToConvert = 34; // an int.
var convertedTemp = tempToConvert.From<Celsius>().To<Fahrenheit>();
Before you decide which one is best for you, don't forget to check the benchmark results here.
I'm working on what I want the library to do when an exception could be thrown. This is when we have the edge cases of values that are too small or too large for the type being converted to.
E.g.:
From a float type with a value close to the max value of a float, converted from Celsius to Fahrenheit. Because a Fahrenheit value is greater than the celsius value, then we can't convert correctly.
Should this throw an exception or just return the original value?
Well, returning the same value would seem like all is well, even though the converted value is wrong. Thinking about this means that for me, it should throw an exception for the calling application to handle.
If anyone has any better ideas, then I would be willing to change this behaviour.
For more information on the project and where it is heading, see the wiki.
I am the sole creator of this library/project. However, I should credit "Google" and "Wikipedia" for helping with the conversion calculations.
This repo and library are using the MIT license.
See the included Contributing File for more information.
David Clark - @CoderDaeer
Daeer-Projects - Daeer Projects
The project does have a unit test project that covers as much as possible of the code base.
There is also a benchmark project that shows how the conversions perform.
This will show more usages and examples of how to consume the library.