<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
var measurements = new (string, string[], string[])[]
("Length", new string[] { "Length" }, new string[] { }),
("Time", new string[] { "Time" }, new string[] { }),
("Mass", new string[] { "Mass" }, new string[] { }),
("Angle", new string[] { "Angle" }, new string[] { }),
("Tempurature", new string[] { "Tempurature" }, new string[] { }),
("ElectricCharge", new string[] { "ElectricCharge" }, new string[] { }),
("Speed", new string[] { "Length", }, new string[] { "Time", }),
("Acceleration", new string[] { "Length", }, new string[] { "Time", "Time", }),
("Force", new string[] { "Mass", "Length", }, new string[] { "Time", "Time", }),
("MassFlow", new string[] { "Mass", }, new string[] { "Time", }),
("MassFlowAcceleration", new string[] { "Mass", }, new string[] { "Time", "Time", }),
("TimeSpace", new string[] { "Time", "Time", }, new string[] { }),
("LinearMass", new string[] { "Mass", "Length", }, new string[] { }),
var viewStrings = measurements.Select(x => string.Join("*", x.Item2) + (x.Item3.Length > 0 ? "/" + string.Join("/", x.Item3) : string.Empty)).ToArray();
var measurementsFormatted = measurements.Select(x => (x.Item1, x.Item2.Clone() as string[], x.Item3.Clone() as string[])).ToArray();
Array.ForEach(measurementsFormatted, x => { Array.Sort(x.Item2); Array.Sort(x.Item3); });
var keys = measurementsFormatted.Select(x => string.Join("*", x.Item2) + (x.Item3.Length > 0 ? "/" + string.Join("/", x.Item3) : string.Empty)).ToArray();
<# { int measurementIndex = 0; foreach (var measurement in measurements) { #>
<# measurementIndex++; } } #>
<# { int measurementIndex = 0; foreach (var measurement in measurements) { #>
<# bool isBaseUnit = measurement.Item2.Length + measurement.Item3.Length == 1; #>
<# bool isDerivedUnit = !isBaseUnit; #>
<# var concatenatedBaseUnits = measurement.Item2.Concat(measurement.Item3); #>
#region <#= measurement.Item1 #>
public struct <#= measurement.Item1 #><T>
internal static Func<T, T>[][] Table = UnitConversionTable.Build<<#= measurement.Item1 #>.Units, T>();
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
internal <#= baseUnit #>.Units _<#= baseUnit #>Units<#= baseUnitIndex + 1 #>;
<# baseUnitIndex++; } } #>
public <#= measurement.Item1 #>(T measurement, MeasurementUnitsSyntaxTypes.<#= measurement.Item1 #>Units units) : this(measurement
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
, units._<#= baseUnit #>Units<#= baseUnitIndex + 1 #>
<# baseUnitIndex++; } } #>
<# if (isDerivedUnit) { #>
public <#= measurement.Item1 #>(T measurement, <#= measurement.Item1 #>.Units units)
throw new NotImplementedException();
public <#= measurement.Item1 #>(T measurement
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
, <#= baseUnit #>.Units <#= baseUnit #>Units<#= baseUnitIndex + 1 #>
<# baseUnitIndex++; } } #>
throw new NotImplementedException();
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
public <#= baseUnit #>.Units <#= baseUnit #>Units<#= baseUnitIndex + 1 #>
get { return _<#= baseUnit #>Units<#= baseUnitIndex + 1 #>; }
if (value != _<#= baseUnit #>Units<#= baseUnitIndex + 1 #>)
_measurement = this[<#= string.Join(", ", concatenatedBaseUnits.Select(x => baseUnitIndex + 1 == ++temp ? "value" : "_" + x + "Units" + temp)) #>];
_<#= baseUnit #>Units<#= baseUnitIndex + 1 #> = value;
<# baseUnitIndex++; } } #>
public T this[MeasurementUnitsSyntaxTypes.<#= measurement.Item1 #>Units units]
get { return this[<#= string.Join(", ", concatenatedBaseUnits.Select(x => "units._" + x + "Units" + ++temp)) #>]; }
public T this[<#= string.Join(", ", concatenatedBaseUnits.Select(x => x + ".Units" + " " + x + "Units" + ++temp)) #>]
T measurement = _measurement;
<# { int baseUnitIndex = 0; foreach (var numerator in measurement.Item2) { #>
if (<#= numerator #>Units<#= baseUnitIndex + 1 #> != _<#= numerator #>Units<#= baseUnitIndex + 1 #>)
if (<#= numerator #>Units<#= baseUnitIndex + 1 #> < _<#= numerator #>Units<#= baseUnitIndex + 1 #>)
measurement = <#= numerator #><T>.Table[(int)_<#= numerator #>Units<#= baseUnitIndex + 1 #>][(int)<#= numerator #>Units<#= baseUnitIndex + 1 #>](measurement);
measurement = <#= numerator #><T>.Table[(int)<#= numerator #>Units<#= baseUnitIndex + 1 #>][(int)_<#= numerator #>Units<#= baseUnitIndex + 1 #>](measurement);
<# foreach (var denominator in measurement.Item3) { #>
if (<#= denominator #>Units<#= baseUnitIndex + 1 #> != _<#= denominator #>Units<#= baseUnitIndex + 1 #>)
if (<#= denominator #>Units<#= baseUnitIndex + 1 #> > _<#= denominator #>Units<#= baseUnitIndex + 1 #>)
measurement = <#= denominator #><T>.Table[(int)_<#= denominator #>Units<#= baseUnitIndex + 1 #>][(int)<#= denominator #>Units<#= baseUnitIndex + 1 #>](measurement);
measurement = <#= denominator #><T>.Table[(int)<#= denominator #>Units<#= baseUnitIndex + 1 #>][(int)_<#= denominator #>Units<#= baseUnitIndex + 1 #>](measurement);
public override bool Equals(object obj)
if (obj is <#= measurement.Item1 #><T>)
return this == (<#= measurement.Item1 #><T>)obj;
<# measurementIndex++; } } #>
#region MeasurementUnitsSyntaxTypes
public static class MeasurementUnitsSyntaxTypes
<# { int measurementIndex = 0; foreach (var measurement in measurements) { #>
<# var concatenatedBaseUnits = measurement.Item2.Concat(measurement.Item3); #>
public struct <#= measurement.Item1 #>Units
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
public <#= baseUnit #>.Units _<#= baseUnit #>Units<#= baseUnitIndex + 1 #>;
<# baseUnitIndex++; } } #>
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
<# baseUnitIndex++; } } #>
<# measurementIndex++; } } #>
<# { int measurementIndex = 0; foreach (var measurement in measurements) { #>
<# var concatenatedBaseUnits = measurement.Item2.Concat(measurement.Item3); #>
#region <#= measurement.Item1 #> Units
public static class <#= measurement.Item1 #>
public static void Map<T>(
<#= measurement.Item1 #>.Units units
<# { int baseUnitIndex = 0; foreach (var baseUnit in concatenatedBaseUnits) { #>
, out <#= baseUnit #>.Units <#= baseUnit #>Units<#= baseUnitIndex + 1 #>
<# baseUnitIndex++; } } #>
throw new NotImplementedException();
<# measurementIndex++; } } #>