Exemplo n.º 1
0
 private static Unit <T> PrefixUnit <T>(PrefixableUnit <T> unit, double multiplier, string namePrefix, string symbolPrefix) where T : IMeasurement <T>
 {
     return(new Unit <T>(
                symbol: symbolPrefix + unit.ToString(),
                defaultsPerUnit: unit.DefaultsPerUnit * multiplier,
                provider: unit.MeasurementProvider
                ));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Returns an IEnumerable with every prefixed unit, based on the specified unit.
        /// </summary>
        /// <typeparam name="T">The type of measurement</typeparam>
        /// <param name="unit">The unit.</param>
        /// <returns></returns>
        public static IEnumerable <Unit <T> > All <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
        {
            Validate.NonNull(unit, nameof(unit));

            yield return(Exa(unit));     yield return(Peta(unit));    yield return(Tera(unit));

            yield return(Giga(unit));    yield return(Mega(unit));    yield return(Kilo(unit));

            yield return(Hecto(unit));   yield return(Deca(unit));    yield return(Deci(unit));

            yield return(Centi(unit));   yield return(Milli(unit));   yield return(Micro(unit));

            yield return(Nano(unit));    yield return(Pico(unit));    yield return(Femto(unit));

            yield return(Atto(unit));    yield return(Yobi(unit));    yield return(Zebi(unit));

            yield return(Exbi(unit));    yield return(Pebi(unit));    yield return(Tebi(unit));

            yield return(Gibi(unit));    yield return(Mebi(unit));    yield return(Kibi(unit));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Represents 2^60 or 1024^6 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Exbi <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1024d * 1024d * 1024d * 1024d * 1024d * 1024d, "exbi", "Ei"));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Represents 1e18 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Exa <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e18, "exa", "E"));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Represents .1 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Deci <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, .1, "deci", "d"));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Represents .01 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Centi <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, .01, "centi", "c"));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Represents 1e-18 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Atto <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e-18, "atto", "a"));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Represents 1e12 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Tera <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e12, "tera", "T"));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Represents 1e-12 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Pico <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e-12, "pico", "p"));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Represents 1e15 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Peta <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e15, "peta", "P"));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Represents 1e-9 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Nano <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e-9, "nano", "n"));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Represents 1e-6 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Micro <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e-6, "micro", "μ"));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Represents 1e6 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Mega <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1e6, "mega", "M"));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Represents 1000 base units
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="unit">The unit.</param>
 /// <returns></returns>
 public static Unit <T> Kilo <T>(PrefixableUnit <T> unit) where T : IMeasurement <T>
 {
     Validate.NonNull(unit, nameof(unit));
     return(PrefixUnit(unit, 1000, "kilo", "k"));
 }