/// <summary>Immediately releases all resources owned by the instance</summary> public void Dispose() { if (this.gameServices != null) { object inputService = this.gameServices.GetService(typeof(IInputService)); if (ReferenceEquals(inputService, this)) { this.gameServices.RemoveService(typeof(IInputService)); } this.gameServices = null; } if (this.touchPanels != null) { CollectionHelper.DisposeItems(this.touchPanels); this.touchPanels = null; } if (this.keyboards != null) { CollectionHelper.DisposeItems(this.keyboards); this.keyboards = null; } if (this.mice != null) { CollectionHelper.DisposeItems(this.mice); this.mice = null; } if (this.gamePads != null) { CollectionHelper.DisposeItems(this.gamePads); this.gamePads = null; } #if !NO_DIRECTINPUT if (this.directInputManager != null) { this.directInputManager.Dispose(); this.directInputManager = null; } #endif #if WINDOWS if (this.windowMessageFilter != null) { this.windowMessageFilter.Dispose(); this.windowMessageFilter = null; } #endif }
public void TestDisposeItems() { var tests = new List <Test>(); var disposable = new TestDisposable(); var test = new Test(); tests.Add(disposable); tests.Add(test); Assert.AreEqual(0, disposable.DisposeCallCount); CollectionHelper.DisposeItems(tests); Assert.AreEqual(1, disposable.DisposeCallCount); }