Converter.Temperature
2.0.1
Prefix Reserved
See the version list below for details.
dotnet add package Converter.Temperature --version 2.0.1
NuGet\Install-Package Converter.Temperature -Version 2.0.1
<PackageReference Include="Converter.Temperature" Version="2.0.1" />
paket add Converter.Temperature --version 2.0.1
#r "nuget: Converter.Temperature, 2.0.1"
// Install Converter.Temperature as a Cake Addin #addin nuget:?package=Converter.Temperature&version=2.0.1 // Install Converter.Temperature as a Cake Tool #tool nuget:?package=Converter.Temperature&version=2.0.1
README
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.
Introduction
These extension methods will convert different types of temperatures to other types.
Temperature types
- Celsius
- Fahrenheit
- Kelvin
- Gas
- Rankine
Data types
- int
- float
- double
- string
Ideas
I had a few ideas on how to do the extension methods but decided on using a fluent style.
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();
The next stage for version 2 is to add an additional usage like this:
var tempToConvert = 34; // an int.
var convertedTemp = tempToConvert.From<Celsius>().To<Fahrenheit>();
What to do for edge cases
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.
More Information
For more information on the project and where it is heading, see the wiki.
If you like the package, then give the repo a star at Converter.Temperature.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Please note that as of version 3.0.0, this library will no longer support dotnet core 3.1.
See the release notes page:
https://github.com/daeer73/Converter.Temperature/wiki/Release-Notes