Table of Contents

Namespace Codebelt.Unitify

Simplify unit measurement and conversion with Codebelt.Unitify, a comprehensive .NET library for managing units with SI unit support, metric prefixes (kilo, mega, milli, micro, etc.), and binary prefixes (kibi, mebi, gibi, etc.).

To get started, use UnitFactory to create SI units, or access predefined SI base units via the Unit class.

Start Here

Begin with UnitFactory — the primary API for creating SI units with custom precision and base values. Call static methods like UnitFactory.CreateMeter() or UnitFactory.CreateWatt() to construct units programmatically.

If you only need standard predefined base units, use the Unit class directly instead (e.g., Unit.Meter, Unit.Kilogram) to avoid factory overhead.

When to Use

Use Codebelt.Unitify when you need to:

  • Work with SI base units (meter, kilogram, second, ampere, kelvin, mole, candela) and derived units
  • Apply metric (decimal) or binary prefixes to create unit variations (e.g., kilometer, megabyte, gibibyte)
  • Convert between different prefix scales while preserving semantic meaning
  • Format units using metric, data-centric, or custom naming conventions

Getting Started

Start here: Call UnitFactory.CreateMeter(), UnitFactory.CreateWatt(), or other static factory methods to construct SI units with your desired precision and base values. UnitFactory is the primary entry point for programmatic unit creation.

Alternative: If you need one of the standard predefined SI base units (meter, kilogram, second, ampere, kelvin, mole, candela), access them directly via static properties on the Unit class (e.g., Unit.Meter, Unit.Kilogram) to avoid factory overhead.

Once you have a unit, you can apply metric or binary prefixes in three ways:

  • Single prefix: Use PrefixUnit to combine a specific prefix with a unit (e.g., create a kilometer from Unit.Meter and DecimalPrefix.Kilo).
  • Full metric scale table: Create a MetricPrefixTable to explore all available decimal-prefix representations (kilo, mega, giga, etc.) at once.
  • Full binary scale table: Create a DataPrefixTable to explore all available binary-prefix representations (kibi, mebi, gibi, etc.) at once for data/storage contexts.

Choose MetricPrefixTable for general scientific and engineering units; choose DataPrefixTable exclusively for data storage and network bandwidth to avoid mixing decimal (1 kB = 1000 bytes) and binary (1 KiB = 1024 bytes) scales.

Availability: .NET 10 and .NET 9

Extension Members

Type Ext Methods
Prefix ⬇️ ToPrefixUnit, ToBaseUnit
PrefixTable ⬇️ QuectoOrDefault, RontoOrDefault, YoctoOrDefault, ZeptoOrDefault, AttoOrDefault, FemtoOrDefault, PicoOrDefault, NanoOrDefault, MicroOrDefault, MilliOrDefault, CentiOrDefault, DeciOrDefault, DecaOrDefault, HectoOrDefault, KiloOrDefault, MegaOrDefault, GigaOrDefault, TeraOrDefault, PetaOrDefault, ExaOrDefault, ZettaOrDefault, YottaOrDefault, RonnaOrDefault, QuettaOrDefault, QuebiOrDefault, RobiOrDefault, KibiOrDefault, MebiOrDefault, GibiOrDefault, TebiOrDefault, PebiOrDefault, ExbiOrDefault, ZebiOrDefault, YobiOrDefault
PrefixUnit ⬇️ ToPrefixValue, ToBaseValue, ToBaseUnit, ToPrefixString, ToMetricPrefixTable, ToDataPrefixTable

Classes

BinaryPrefix

Defines a binary unit prefix for multiples of measurement for data that refers strictly to powers of 2. This class cannot be inherited.

DataPrefixTable

Represents a table of both binary and metric prefixes for units of measure, optimized for data quantity and transmission measurement standards.

DecimalPrefix

Defines a decimal (metric) unit prefix for multiples and submultiples of measurement that refers strictly to powers of 10. This class cannot be inherited.

MetricPrefixTable

Represents a table of metric prefixes for units of measure, optimized for metric measurement standards.

Prefix

Represents the base class from which all implementations of unit prefix that can can be expressed as either a multiple or a submultiple should derive.

PrefixExtensions

Extension methods for the IPrefix interface.

PrefixTable

Represents a table of unit prefixes, indicating multiples or submultiples of a base unit.

PrefixTableExtensions

Extension methods for the PrefixTable class.

PrefixUnit

Represents the prefix of a unit of measurement.

PrefixUnitExtensions

Extension methods for the IPrefixUnit interfacce.

PrefixUnitFormatter

Defines the string formatting of objects having an implementation of IPrefixUnit.

Unit

Represents the base class from which all implementations of a unit of measure should derive.

UnitFactory

Provides a set of static methods for generating different types of unit of measure and the option to define your own with CreateUnit(string, string, string, double, IPrefix, Action<UnitFormatOptions>).

UnitFormatOptions

Configuration options for implementations of IBaseUnit.

UnitFormatter

Defines the string formatting of objects having an implementation of IUnit.

Structs

BaseUnit

Represents a base unit of measurement, including its category, name, and symbol.

Interfaces

IBaseUnit

Defines a base unit of measure, including its category, name, and symbol.

IPrefix

Defines a unit prefix that can can be expressed as either a multiple or a submultiple of the unit of measurement.

IPrefixUnit

Defines a unit of measurement that is used as a standard for measurement of the same kind of quantity. Any other quantity of that kind can be expressed as a multiple or fraction of the unit of measurement.

IUnit

Defines a unit of measure that is used as a standard for measurement of the same kind of quantity.

Enums

NamingStyle

Specifies ways that a string must be represented in terms of naming style.

PrefixStyle

Specifies ways that a string must be represented in terms of prefix style.