Univertall 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Univertall --version 1.0.0                
NuGet\Install-Package Univertall -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Univertall" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Univertall --version 1.0.0                
#r "nuget: Univertall, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Univertall as a Cake Addin
#addin nuget:?package=Univertall&version=1.0.0

// Install Univertall as a Cake Tool
#tool nuget:?package=Univertall&version=1.0.0                

Here's your updated README with the requested table of supported units (including custom units):

UniVertAll

Publish to NuGet

UniVertAll is a versatile unit conversion library for .NET developers. It supports a wide range of units and provides a fluent API for easy and intuitive conversions. The library is compatible with .NET 6, .NET 7, .NET 8, and .NET 9.

License: MIT

Features

  • Comprehensive Support: Includes various units (length, mass, power, temperature, volume, and more).
  • Fluent API: Simplifies unit conversion with an intuitive syntax.
  • Customizable: Extend the library with your own units and conversions.
  • Thread-Safe: Designed for concurrent applications.
  • Compatible: Works with multiple .NET versions.
  • NuGet Distribution: Easily installable via NuGet Package Manager.

Installation

Install the UniVertAll library via NuGet:

NuGet Version NuGet Downloads

Using .NET CLI:

dotnet add package UniVertAll

Using Package Manager:

Search for UniVertAll in the NuGet Package Manager within Visual Studio and install it.

Supported Units

Here’s a list of all the units supported by UniVertAll:

Category Units Supported
Length Meter, Kilometer, Centimeter, Millimeter, Micrometer, Nanometer, Inch, Foot, Yard, Mile, Nautical Mile
Mass Kilogram, Gram, Milligram, Microgram, Ton, Metric Ton, Long Ton, Short Ton, Pound, Ounce, Stone, Carat
Volume Cubic Meter, Liter, Milliliter, Gallon (US), Gallon (UK), Quart, Pint, Cup, Fluid Ounce, Tablespoon, Teaspoon
Power Watt, Kilowatt, Megawatt, Gigawatt, Horsepower (Metric), Horsepower (Imperial)
Temperature Celsius, Fahrenheit, Kelvin
Pressure Pascal, Kilopascal, Bar, Atmosphere, Torr, PSI (Pounds per Square Inch)
Volume Flow Rate Cubic Meter per Second, Liter per Second, Gallon per Minute (US), Gallon per Hour (US), Cubic Feet per Second, Cubic Feet per Minute, Cubic Inch per Second, Cubic Inch per Minute
Angle Degree, Radian, Gradian
Digital Bit, Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, Exabyte
Fuel Economy Miles per Gallon (US), Miles per Gallon (Imperial), Liters per 100 Kilometers, Kilometers per Liter
Force Newton, Kilonewton, Pound-Force, Ounce-Force
Custom CustomUnit (User-defined, such as UnitA, UnitB, etc.)

Using Univertall

UniVertAll uses a fluent API to provide intuitive and easy-to-use conversions. Below are some examples showcasing its functionality:

1. Length Conversion

using UnitConverter.Units.Length;

double meters = 5000;
double kilometers = meters.ConvertLength().From(LengthUnit.Meter).To(LengthUnit.Kilometer);
Console.WriteLine($"{meters} Meters is equal to {kilometers} Kilometers.");

3. Volume Conversion

using UnitConverter.Units.Volume;

double liters = 3.78541;
double gallons = liters.ConvertVolume().From(VolumeUnit.Liter).To(VolumeUnit.Gallon);
Console.WriteLine($"{liters} Liters is equal to {gallons} Gallons.");

4. Power Conversion

using UnitConverter.Units.Power;

double watts = 746;
double horsepower = watts.ConvertPower().From(PowerUnit.Watt).To(PowerUnit.MetricHorsepower);
Console.WriteLine($"{watts} Watts is equal to {horsepower} Horsepower.");

6. Angle Conversion

using UnitConverter.Units.Angle;

double degrees = 180;
double radians = degrees.ConvertAngle().From(AngleUnit.Degree).To(AngleUnit.Radian);
Console.WriteLine($"{degrees} Degrees is equal to {radians} Radians.");

Extending with Custom Units

UniVertAll is highly extensible. You can define your custom units and conversions by inheriting from the BaseUnitConverter class, as shown above. This makes the library flexible and adaptable to unique domain-specific requirements. Here is an example:

using UnitConverter.Base;

public enum CustomUnit { UnitA, UnitB }

public class CustomConverter : BaseUnitConverter<CustomUnit>
{
    protected override double ToBaseUnit(double value, CustomUnit fromUnit)
    {
        return fromUnit switch
        {
            CustomUnit.UnitA => value * 10,  // Example: 1 UnitA = 10 Base Units
            CustomUnit.UnitB => value / 2,  // Example: 1 UnitB = 0.5 Base Units
            _ => throw new ArgumentOutOfRangeException(nameof(fromUnit), fromUnit, null)
        };
    }

    protected override double FromBaseUnit(double value, CustomUnit toUnit)
    {
        return toUnit switch
        {
            CustomUnit.UnitA => value / 10,  // Convert Base Unit to UnitA
            CustomUnit.UnitB => value * 2,   // Convert Base Unit to UnitB
            _ => throw new ArgumentOutOfRangeException(nameof(toUnit), toUnit, null)
        };
    }
}

// Usage
var customConverter = new CustomConverter();
double result = customConverter.Convert(5, CustomUnit.UnitA, CustomUnit.UnitB);
Console.WriteLine($"5 UnitA is equal to {result} UnitB.");

Documentation

XML documentation is included for all public classes and methods, accessible in your IDE. You can generate documentation using tools like DocFX or Sandcastle.

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a new branch for your feature: git checkout -b feature-name.
  3. Commit your changes: git commit -m "Add new feature".
  4. Push your branch: git push origin feature-name.
  5. Open a pull request.

Ensure your code adheres to the project’s coding style and includes tests.

License

UniVertAll is licensed under the MIT License. See the LICENSE file for more details.

Contact

For questions or feedback:

  • Open an issue on the GitHub repository.
  • We welcome your suggestions and contributions!

Thank you for using UniVertAll! We hope it simplifies your unit conversion needs. 😊


Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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
1.1.0 87 11/22/2024
1.0.0 105 11/19/2024