public Alergen GetAlergen(string name) { Alergen ret = Alergens.Where(x => x.Name == name).FirstOrDefault(); if (ret == null) { ret = new Alergen(name); Alergens.Add(ret); } return(ret); }
public Food(string input, Data data) { Match m = Regex.Match(input, @"([^\(]*) \(contains ([^)]*)\)"); string ingredients = m.Groups[1].Value; string alergens = m.Groups[2].Value; string[] ingredientsArr = ingredients.Split(' '); foreach (string ingrName in ingredientsArr) { Ingredient ingr = data.GetIngredient(ingrName.Trim()); Ingredients.Add(ingr); } string[] alergensArr = alergens.Split(','); foreach (string alerName in alergensArr) { Alergen aler = data.GetAlergen(alerName.Trim()); Alergens.Add(aler); } }