Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

ktsu.Semantics.Quantities.Float

Storage-type aliases that bind every ktsu.Semantics.Quantities type to float, so you write Mass instead of Mass<float>, project-wide.

License NuGet Version NuGet Version NuGet Downloads GitHub commit activity GitHub contributors GitHub Actions Workflow Status

ktsu.Semantics.Quantities.Float is a satellite of ktsu.Semantics.Quantities in the ktsu.Semantics family. Read the core package README first for the quantity API itself.

Introduction

Every quantity in ktsu.Semantics.Quantities is generic over its numeric storage type, so you normally write Mass<float>, Speed<float>, and so on. If a project uses one storage type throughout, that generic argument is noise.

This package is props-only. It ships no assembly, just a buildTransitive props file that injects one C# global-using alias per quantity, binding each open generic type to float. Reference it and you can write Mass, Speed, Force3D with no generic argument, and every quantity resolves to its float form. The aliases are real Mass<float> (and so on), so they interoperate with the entire API with no conversion.

Installing this package also pulls in the matching version of ktsu.Semantics.Quantities as a dependency, so it is the only reference you need.

Installation

Package Manager Console

Install-Package ktsu.Semantics.Quantities.Float

.NET CLI

dotnet add package ktsu.Semantics.Quantities.Float

Package Reference

<PackageReference Include="ktsu.Semantics.Quantities.Float" Version="x.y.z" />

Usage Example

using ktsu.Semantics.Quantities;   // types resolve to their float form via the injected aliases

Mass mass = Mass.FromKilogram(10.0f);
Speed speed = Speed.FromMeterPerSecond(15.0f);
Mass total = mass + Mass.FromKilogram(2.0f);   // still a Mass<float>, full identity

Force3D f = new() { X = 3.0f, Y = 4.0f, Z = 0.0f };
ForceMagnitude mag = f.Magnitude();            // 5.0

Under the hood the injected alias looks like this (one line per quantity, roughly 220 in total):

<Using Include="ktsu.Semantics.Quantities.Mass&lt;float&gt;" Alias="Mass" />

Use exactly one storage-type alias package per project

The aliases are project-wide global usings keyed on the bare type name (Mass, Speed, ...). Referencing two flavor packages in the same project would define the same alias name twice (one bound to float, one to another type), which is a compile error. So reference exactly one of:

A project that genuinely needs mixed storage types should skip the alias packages and reference ktsu.Semantics.Quantities directly, writing the closed generic (Mass<float>) explicitly.

The alias lists are generated from the quantity catalogue by scripts/Generate-AliasProps.ps1 and validated in CI, so they stay in lockstep with the quantities the core package emits.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.