From b3301d90417640263985e79fd70de7776b4f54a3 Mon Sep 17 00:00:00 2001 From: mpolicki Date: Tue, 18 Aug 2020 11:17:23 +0200 Subject: [PATCH 1/2] add IDisposable implementation --- source/VirtualDesktop/VirtualDesktop.cs | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/source/VirtualDesktop/VirtualDesktop.cs b/source/VirtualDesktop/VirtualDesktop.cs index cfb0e78..3f7a235 100644 --- a/source/VirtualDesktop/VirtualDesktop.cs +++ b/source/VirtualDesktop/VirtualDesktop.cs @@ -14,7 +14,7 @@ namespace WindowsDesktop [ComInterfaceWrapper] [DebuggerDisplay("{Id}")] [UsedImplicitly(ImplicitUseTargetFlags.Members)] - public partial class VirtualDesktop : ComInterfaceWrapperBase + public partial class VirtualDesktop : ComInterfaceWrapperBase, IDisposable { /// /// Gets the unique identifier for this virtual desktop. @@ -86,5 +86,35 @@ public VirtualDesktop GetRight() return null; } } + +#region IDisposable + private bool disposed = false; + + /// + /// Disposes of this . + /// + /// If , disposes of managed objects. + protected virtual void Dispose(bool disposeOfManagedObjects) + { + if(!disposed) + { + if(disposeOfManagedObjects) + { + Remove(); + } + + disposed = true; + } + } + + /// + /// Disposes of this . + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } +#endregion } } From c9e0c614fda305f3dc8bd463f8c4f4e577835215 Mon Sep 17 00:00:00 2001 From: Miroslav Policki Date: Tue, 25 Aug 2020 01:48:59 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: monotone --- source/VirtualDesktop/VirtualDesktop.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/VirtualDesktop/VirtualDesktop.cs b/source/VirtualDesktop/VirtualDesktop.cs index 3f7a235..7eb66c7 100644 --- a/source/VirtualDesktop/VirtualDesktop.cs +++ b/source/VirtualDesktop/VirtualDesktop.cs @@ -88,7 +88,7 @@ public VirtualDesktop GetRight() } #region IDisposable - private bool disposed = false; + private bool _disposed = false; /// /// Disposes of this . @@ -96,14 +96,14 @@ public VirtualDesktop GetRight() /// If , disposes of managed objects. protected virtual void Dispose(bool disposeOfManagedObjects) { - if(!disposed) + if (!this._disposed) { - if(disposeOfManagedObjects) + if (disposeOfManagedObjects) { - Remove(); + this.Remove(); } - disposed = true; + this._disposed = true; } } @@ -112,7 +112,7 @@ protected virtual void Dispose(bool disposeOfManagedObjects) /// public void Dispose() { - Dispose(true); + this.Dispose(true); GC.SuppressFinalize(this); } #endregion