public static InventoryType[] GetInventoryTypes(this Table table) { var inventoryTypes = new List <InventoryType>(); foreach (var tableRow in table.Rows) { var name = tableRow["Name"]; int capacity = int.Parse(tableRow["Capacity"]); CargoSize size = (CargoSize)Enum.Parse(typeof(CargoSize), tableRow["CargoSize"]); var inventoryType = new InventoryType(name, capacity, size); inventoryTypes.Add(inventoryType); } return(inventoryTypes.ToArray()); }
public InventoryType(string name, int capacity, CargoSize size) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Argument is null or whitespace", nameof(name)); } if (capacity <= 0) { throw new ArgumentOutOfRangeException(nameof(capacity)); } if (!Enum.IsDefined(typeof(CargoSize), size)) { throw new ArgumentOutOfRangeException(nameof(size)); } Name = name; Capacity = capacity; Size = size; }