aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/CommonExtensions.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-30 12:35:38 -0500
committerGitHub <noreply@github.com>2022-10-30 12:35:38 -0500
commitdbe3a9e82036a0db8049f3b884342dc98cc98d58 (patch)
tree6fae10d316a7564f788cae6ca19fbc9d0236e36b /src/slskd/Common/CommonExtensions.cs
parente483a797f8f2a1b50397a6a72cac03430ac5dcb6 (diff)
parent4489434a5d5580b8bf74bc0a16512545e0dcb0f6 (diff)
downloadslskd-dbe3a9e82036a0db8049f3b884342dc98cc98d58.tar.gz
Merge pull request #713 from slskd/more-cleanup
More Network cleanup
Diffstat (limited to 'src/slskd/Common/CommonExtensions.cs')
-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>