示例#1
0
        private void ClearExisting()
        {
            if (_car != null && CacheSize > 0)
            {
                var existing = _previousCars.FirstOrDefault(x => x.Id == _car.MainKn5File);
                if (existing != null)
                {
                    _previousCars.Remove(existing);
                    _previousCars.Add(existing);
                }
                else if (_carWrapper.OfType <Kn5RenderableCar>().Any())
                {
                    if (_previousCars.Count >= CacheSize)
                    {
                        var toRemoval = _previousCars[0];
                        toRemoval.Objects.DisposeEverything();
                        _previousCars.RemoveAt(0);
                    }

                    _previousCars.Add(new PreviousCar {
                        Id      = _car.MainKn5File,
                        Objects = _carWrapper.ToList()
                    });

                    _carWrapper.Clear();
                    return;
                }
            }

            _carWrapper.DisposeEverything();
        }