TrickyMottram.UnitConversion.Weight 1.0.1

dotnet add package TrickyMottram.UnitConversion.Weight --version 1.0.1
                    
NuGet\Install-Package TrickyMottram.UnitConversion.Weight -Version 1.0.1
                    
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="TrickyMottram.UnitConversion.Weight" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TrickyMottram.UnitConversion.Weight" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="TrickyMottram.UnitConversion.Weight" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TrickyMottram.UnitConversion.Weight --version 1.0.1
                    
#r "nuget: TrickyMottram.UnitConversion.Weight, 1.0.1"
                    
#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.
#addin nuget:?package=TrickyMottram.UnitConversion.Weight&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=TrickyMottram.UnitConversion.Weight&version=1.0.1
                    
Install as a Cake Tool

TrickyMottram.UnitConversion.Weight

Weight unit conversion implementation for the TrickyMottram Unit Conversion libraries.

This package provides an implementation of IUnitConverter and IUnitRegistry for converting between metric and imperial weight units. It is part of the TrickyMottram.UnitConversion ecosystem.

✨ Features

  • Supports a wide range of units including milligram, kilogram, ton, ounce, pound, stone, and hundredweight
  • Enum and string-based conversion APIs
  • Works seamlessly with UnitConversionService
  • Dependency-injection friendly design with Microsoft.Extensions.Logging support
  • Provides unit discovery through a registry for UI binding

🔧 Usage Example

Add to Dependency Injection

services.AddSingleton<IUnitConverter, WeightConverter>();
services.AddSingleton<IUnitRegistry, WeightUnitRegistry>();

Convert via UnitConversionService

public class WeightController : ControllerBase
{
    private readonly UnitConversionService _service;

    public WeightController(UnitConversionService service)
    {
        _service = service;
    }

    [HttpGet]
    public IActionResult ConvertWeight(double value, string from, string to)
    {
        var result = _service.Convert(value, from, to);
        return Ok(result);
    }
}

Strongly Typed Conversion

double pounds = new WeightConverter(logger)
    .Convert(1.0, WeightUnit.Kilogram, WeightUnit.Pound); // ~2.20462

📚 Main Types

  • TrickyMottram.UnitConversion.Weight.WeightConverter
  • TrickyMottram.UnitConversion.Weight.Registry.WeightUnitRegistry
  • TrickyMottram.UnitConversion.Weight.Enums.WeightUnit
  • TrickyMottram.UnitConversion.Weight.Extensions.WeightUnitExtensions

📦 Package Metadata

  • Target Framework: .NET 8
  • License: MIT
  • Source: GitHub Repository
  • Tags: unit conversion, weight, mass, measurement, dotnet

✅ Contributing

Suggestions for additional units or formatting improvements are welcome via GitHub Issues or pull requests.


© Tricky Mottram

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

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.0.1 107 6/7/2025