Class 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>).
Examples
Create SI units with predefined base values using factory methods. This example demonstrates factory methods for different unit types (meter, watt, byte, and second), each creating a fully-configured unit instance with a base value so you can immediately start formatting and working with the result:
using System;
using Codebelt.Unitify;
namespace Unitify.Samples;
public class UnitFactoryExample
{
public static void Main()
{
// Create a meter unit
var meter = UnitFactory.CreateMeter(100);
Console.WriteLine($"Distance: {meter}");
// Create a watt unit
var watt = UnitFactory.CreateWatt(1500);
Console.WriteLine($"Power: {watt}");
// Create a byte unit for data storage
var byte_unit = UnitFactory.CreateByte(1024);
Console.WriteLine($"Data: {byte_unit}");
// Create a second unit for time
var second = UnitFactory.CreateSecond(3600);
Console.WriteLine($"Time: {second}");
}
}
public static class UnitFactory
- Inheritance
-
UnitFactory
Methods
CreateAmpere(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Current in amperes.
public static IPrefixUnit CreateAmpere(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Current in amperes.
- See Also
CreateBecquerel(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Radioactivity in becquerels.
public static IPrefixUnit CreateBecquerel(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Radioactivity in becquerels.
- See Also
CreateBit(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Data Quantity in bits.
public static IPrefixUnit CreateBit(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe optional prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Data Quantity in bits.
- See Also
CreateBitPerSecond(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Transmission Rate in bits per second.
public static IPrefixUnit CreateBitPerSecond(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Transmission Rate in bits per second.
- See Also
CreateByte(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Data Quantity in bytes.
public static IPrefixUnit CreateByte(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe optional prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Data Quantity in bytes.
- See Also
CreateCandela(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Luminous Intensity in candelas.
public static IPrefixUnit CreateCandela(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Luminous Intensity in candelas.
- See Also
CreateCelsius(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Temperature in degrees Celsius.
public static IPrefixUnit CreateCelsius(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Temperature in degrees Celsius.
- See Also
CreateCoulomb(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Charge in coulombs.
public static IPrefixUnit CreateCoulomb(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Charge in coulombs.
- See Also
CreateFarad(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Capacitance in farads.
public static IPrefixUnit CreateFarad(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Capacitance in farads.
- See Also
CreateGram(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Mass in grams.
public static IPrefixUnit CreateGram(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Mass in grams.
- See Also
CreateGray(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Absorbed Dose in grays.
public static IPrefixUnit CreateGray(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Absorbed Dose in grays.
- See Also
CreateHenry(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Inductance in henries.
public static IPrefixUnit CreateHenry(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Inductance in henries.
- See Also
CreateHertz(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Frequency in hertz.
public static IPrefixUnit CreateHertz(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Frequency in hertz.
- See Also
CreateJoule(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Energy in joules.
public static IPrefixUnit CreateJoule(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Energy in joules.
- See Also
CreateKatal(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Catalytic Activity in katals.
public static IPrefixUnit CreateKatal(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Catalytic Activity in katals.
- See Also
CreateKelvin(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Temperature in kelvin.
public static IPrefixUnit CreateKelvin(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Temperature in kelvin.
- See Also
CreateKilogram(double, Action<UnitFormatOptions>)
Creates a unit of measure for Mass in kilograms.
public static IPrefixUnit CreateKilogram(double value, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Mass in kilograms.
- See Also
CreateLumen(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Luminous Flux in lumens.
public static IPrefixUnit CreateLumen(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Luminous Flux in lumens.
- See Also
CreateLux(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Illuminance in lux.
public static IPrefixUnit CreateLux(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Illuminance in lux.
- See Also
CreateMeter(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Length in meters.
public static IPrefixUnit CreateMeter(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Length in meters.
- See Also
CreateMole(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Amount of Substance in moles.
public static IPrefixUnit CreateMole(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Amount of Substance in moles.
- See Also
CreateNewton(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Force in newtons.
public static IPrefixUnit CreateNewton(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Force in newtons.
- See Also
CreateOhm(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Resistance in ohms.
public static IPrefixUnit CreateOhm(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Resistance in ohms.
- See Also
CreatePascal(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Pressure in pascals.
public static IPrefixUnit CreatePascal(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Pressure in pascals.
- See Also
CreateRadian(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Plane Angle in radians.
public static IPrefixUnit CreateRadian(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Plane Angle in radians.
- See Also
CreateSecond(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Time in seconds.
public static IPrefixUnit CreateSecond(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Time in seconds.
- See Also
CreateSiemens(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Conductance in siemens.
public static IPrefixUnit CreateSiemens(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Conductance in siemens.
- See Also
CreateSievert(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Equivalent Dose in sieverts.
public static IPrefixUnit CreateSievert(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Equivalent Dose in sieverts.
- See Also
CreateSteradian(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Solid Angle in steradians.
public static IPrefixUnit CreateSteradian(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Solid Angle in steradians.
- See Also
CreateTesla(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Magnetic Flux Density in teslas.
public static IPrefixUnit CreateTesla(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Magnetic Flux Density in teslas.
- See Also
CreateUnit(string, string, string, double, IPrefix, Action<UnitFormatOptions>)
Creates a custom unit of measure.
public static IPrefixUnit CreateUnit(string category, string name, string symbol, double value, IPrefix prefix, Action<UnitFormatOptions> setup = null)
Parameters
categorystringThe category of the unit.
namestringThe name of the unit.
symbolstringThe symbol of the unit.
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A custom unit of measure.
CreateVolt(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Electric Potential in volts.
public static IPrefixUnit CreateVolt(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Electric Potential in volts.
- See Also
CreateWatt(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Power in watts.
public static IPrefixUnit CreateWatt(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Power in watts.
- See Also
CreateWeber(double, IPrefix, Action<UnitFormatOptions>)
Creates a unit of measure for Magnetic Flux in webers.
public static IPrefixUnit CreateWeber(double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe value of the unit.
prefixIPrefixThe prefix of the unit.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- IPrefixUnit
A unit of measure for Magnetic Flux in webers.
- See Also