public bool IsValid() { if (Contains == null) { return(false); } if (Type == WordsRequestType.Random) { if (Contains.Any()) { return(false); } return(IsValidCount()); } if (Type == WordsRequestType.ContainingKeyPairs) { if (!Contains.Any()) { return(false); } return(IsValidCount()); } return(false); }
public void Deepen() { if (Deepened) { return; } var copy = new List <BagCounter>(); foreach (var cpy in Contains) { copy.Add(new BagCounter() { Count = cpy.Count, Name = cpy.Name }); } foreach (var bag in copy) { var foundBag = Bags.FirstOrDefault(x => x.BagName == bag.Name); if (foundBag == null) { continue; } if (!foundBag.Deepened) { foundBag.Deepen(); } foreach (var toAdd in foundBag.Contains) { if (Contains.Any(x => x.Name == toAdd.Name)) { var index = Contains.FindIndex(x => x.Name == toAdd.Name); Contains[index].Count += toAdd.Count * bag.Count; } else { Contains.Add(new BagCounter() { Name = toAdd.Name, Count = toAdd.Count * bag.Count }); } } } Deepened = true; }