public IEnumerable <Detal> ReleaseStorage(Detal detal) { var list = this.GetListByType(detal); foreach (var item in list) { yield return(item); } list.Clear(); Console.WriteLine($"List after cleansing:{list.Count}, {this.GetListByType(detal).Count}"); list.Add(detal); }
public void Add(Detal detal) { if (detal == null) { throw new ArgumentNullException("detail"); } if (detal.Price == 0) { return; } if (detal is Wheel wheel && wheels.Count < 4) { wheels.Add(wheel); }
protected override void InternalAct() { var key = Program.Rnd.Next(0, 2); Detal detal = null; if (key == 0) { detal = new Wheel(100); } else if (key == 1) { detal = new Engine(1500); } zavod.Add(detal); zavod.ShowState(); }
public bool AddDetal(Detal detal) { var type = detal.GetType(); var list = GetListByType(detal); if (list == null) { throw new ArgumentException("wut?"); } if (list.Count >= list.Capacity) { return(false); } list.Add(detal); return(true); }
protected List <Detal> GetListByType(Detal detal) { switch (detal) { case SteeringWheel sw: return(steeringWheels); case Sit sit: return(sits); case Engine e: return(engines); case Wheel w: return(wheels); } return(null); }
public void Add(Detal detal) { if (detal == null) { throw new ArgumentNullException("detail"); } if (detal.Price == 0) { return; } foreach (var c in cars) { bool carTookDetail = c.AddDetal(detal); if (carTookDetail) { return; } } bool storageNotFull = storage.AddDetal(detal); if (storageNotFull) { return; } var detals = storage.ReleaseStorage(detal); //cars.Add(new Car().PutDetal(detals.ToArray())); var aNewCar = new Car(); aNewCar.PutDetal(detals.ToArray()); cars.Add(aNewCar); }