feat: add IDisposable support to WindowSystem

This is because SamplePlugin contains an example of IDisposable that will never be called when calling RemoveAllWindows or RemoveWindow
This commit is contained in:
wolfcomp 2023-01-15 03:52:24 +01:00
parent dae1b63797
commit 3dfc720878
No known key found for this signature in database
GPG key ID: 576FC5D242626D29

View file

@ -81,13 +81,25 @@ public class WindowSystem
if (!this.windows.Contains(window)) if (!this.windows.Contains(window))
throw new ArgumentException("This window is not registered on this WindowSystem."); throw new ArgumentException("This window is not registered on this WindowSystem.");
if (window is IDisposable disposable)
disposable.Dispose();
this.windows.Remove(window); this.windows.Remove(window);
} }
/// <summary> /// <summary>
/// Remove all windows from this <see cref="WindowSystem"/>. /// Remove all windows from this <see cref="WindowSystem"/>.
/// </summary> /// </summary>
public void RemoveAllWindows() => this.windows.Clear(); public void RemoveAllWindows()
{
foreach (var window in this.windows)
{
if (window is IDisposable disposable)
disposable.Dispose();
}
this.windows.Clear();
}
/// <summary> /// <summary>
/// Get a window by name. /// Get a window by name.