public static void removeAllCommodities(ItemInventory inventory) { foreach (var item in inventory.toArray()) { var hasinv = item as IHasInventoryItem; if (hasinv != null) removeAllCommodities(hasinv.getInventory()); } inventory.removeAll(item => item.IsCommodity); }