Item parseAddCommand(string[] args, ref int idx) { if (args.Length <= idx) { Console.WriteLine("Expected description."); displayAddCommandInstructions(); return(null); } var description = args[idx++]; var newId = ItemGroup.allocateId(); var item = new Item(newId, description); addItem(item); this.ItemGroupFile.save(); return(item); }
// If x is a number, finds the task with that id // returns null if it doesn't exist. // If x is a string makes a new task with that description Item createOrGetItemFromIdOrString(string x) { Item newItem; // Extract an id or description UInt32 itemId; if (UInt32.TryParse(x, out itemId)) { // It's a task id newItem = ItemGroup.Items.getItemById(itemId); // Assume newItem isn't null because we checked above } else { // Createa a new item based on description and add it to the item group newItem = new Item(ItemGroup.allocateId(), x); addItem(newItem); } return(newItem); }