aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/CommonExtensions.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 561162d4..9cf80a4a 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -95,6 +95,22 @@ namespace slskd
}
/// <summary>
+ /// Safely disposes this object without throwing if it is already exposed.
+ /// </summary>
+ /// <param name="obj">The object.</param>
+ public static void TryDispose(this IDisposable obj)
+ {
+ try
+ {
+ obj?.Dispose();
+ }
+ catch (ObjectDisposedException)
+ {
+ // no-op; something else beat us to it
+ }
+ }
+
+ /// <summary>
/// Recursively retrieves all properties.
/// </summary>
/// <param name="type">The type from which to retrieve properties.</param>