private static async Task<bool> LoadPacks() { var pack = await ReadUnitsPack("DefaultUnits.json"); // parse all the units and add to the units collection foreach (var unit in pack.Units) { BaseUnit newUnit = new BaseUnit(unit.Name, unit.Description, unit.Category, unit.BaseUnitValue); _units.Add(newUnit); } return true; }
public static IUnit RegisterUnit(string name, string description, UnitCategory category, double baseUnitValue) { // check for null strings if (String.IsNullOrWhiteSpace(name)) throw new ArgumentException($"Name connot be null or empty"); // check if the unit exists for the category var unit = UnitFromName(name, category); if (unit != null) throw new ArgumentException($"Unit '{name}' for category '{category}' already registered"); var newUnit = new BaseUnit(name, description, category, baseUnitValue); _units.Add(newUnit); return newUnit; }