Beispiel #1
0
        static SIPrefix()
        {
            _instances = new List <SIPrefix>
            {
                (_prefix_yocto = new SIPrefix("yocto", "y", -24)),
                (_prefix_zepto = new SIPrefix("zepto", "z", -21)),
                (_prefix_atto = new SIPrefix("atto", "a", -18)),
                (_prefix_femto = new SIPrefix("femto", "f", -15)),
                (_prefix_pico = new SIPrefix("pico", "p", -12)),
                (_prefix_nano = new SIPrefix("nano", "n", -9)),
                (_prefix_micro = new SIPrefix("micro", "µ", -6)),
                (_prefix_milli = new SIPrefix("milli", "m", -3)),
                (_prefix_centi = new SIPrefix("centi", "c", -2)),
                (_prefix_deci = new SIPrefix("deci", "d", -1)),
                (_prefix_none = new SIPrefix("", "", 0)),
                (_prefix_deca = new SIPrefix("deca", "da", 1)),
                (_prefix_hecto = new SIPrefix("hecto", "h", 2)),
                (_prefix_kilo = new SIPrefix("kilo", "k", 3)),
                (_prefix_mega = new SIPrefix("mega", "M", 6)),
                (_prefix_giga = new SIPrefix("giga", "G", 9)),
                (_prefix_tera = new SIPrefix("tera", "T", 12)),
                (_prefix_peta = new SIPrefix("peta", "P", 15)),
                (_prefix_exa = new SIPrefix("exa", "E", 18)),
                (_prefix_zetta = new SIPrefix("zetta", "Z", 21)),
                (_prefix_yotta = new SIPrefix("yotta", "Y", 24))
            };

            _nonePrefixList      = new SIPrefixList(new SIPrefix[] { _prefix_none });
            _allPrefixes         = new SIPrefixList(_instances);
            _multipleOf3Prefixes = new SIPrefixList(new SIPrefix[] {
                _prefix_yocto,
                _prefix_zepto,
                _prefix_atto,
                _prefix_femto,
                _prefix_pico,
                _prefix_nano,
                _prefix_micro,
                _prefix_milli,
                _prefix_none,
                _prefix_kilo,
                _prefix_mega,
                _prefix_giga,
                _prefix_tera,
                _prefix_peta,
                _prefix_exa,
                _prefix_zetta,
                _prefix_yotta
            });

            _prefixByExponent = new Dictionary <int, SIPrefix>();
            foreach (var prefix in _instances)
            {
                _prefixByExponent.Add(prefix.Exponent, prefix);
            }
        }
Beispiel #2
0
        public UnitWithLimitedPrefixes(IUnit unit, IEnumerable <SIPrefix> allowedPrefixes)
        {
            if (null == unit)
            {
                throw new ArgumentNullException(nameof(unit));
            }

            _unit = unit;

            if (null != allowedPrefixes)
            {
                var l = new HashSet <SIPrefix>(_unit.Prefixes);
                l.IntersectWith(allowedPrefixes);
                _prefixes = new SIPrefixList(l);
            }
        }