Converter.Temperature 2.1.1

.NET 5.0 .NET Core 3.1
Install-Package Converter.Temperature -Version 2.1.1
dotnet add package Converter.Temperature --version 2.1.1
<PackageReference Include="Converter.Temperature" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Converter.Temperature --version 2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Converter.Temperature, 2.1.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Converter.Temperature as a Cake Addin
#addin nuget:?package=Converter.Temperature&version=2.1.1

// Install Converter.Temperature as a Cake Tool
#tool nuget:?package=Converter.Temperature&version=2.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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
  • long
  • 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.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
2.1.1 59 6/3/2022
2.0.1 99 4/21/2022
2.0.0 105 1/8/2022
1.1.0 123 12/2/2021

Please note that as of version 3.0.0, this library will no longer support dotnet core 3.1.

     See the details at the following link.

     https://github.com/Daeer-Projects/Converter.Temperature/wiki/Release-Notes