private void RegisterKnownUnit(KnownUnit unit) { units.Add(Tuple.Create(unit.Factor, unit.Dimension), unit); unitsBySymbol.Add(unit.Symbol, unit); if (unit.Factor.Equals(1)) { this.coherentUnits.Add(unit.Dimension, unit); } }
private void EnsureUnitIsNotRegistered(KnownUnit unit) { if (this.units.Values.Any(u => u.Symbol == unit.Symbol)) { throw new InvalidOperationException(Messages.UnitSymbolAlreadyKnown.FormatWith(unit.Symbol)); } KnownUnit collision; if (this.units.TryGetValue(Tuple.Create(unit.Factor, unit.Dimension), out collision)) { throw new InvalidOperationException(Messages.UnitAlreadyKnown.FormatWith(unit, collision)); } }