aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/CommonExtensions.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-10-29 18:08:33 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-10-29 18:08:33 -0500
commit6eac4a56dfd2a9c7729f63b3de329480253b5656 (patch)
tree74e459f1eaa8c2bf872271760442f64101ffe002 /src/slskd/Common/CommonExtensions.cs
parent53273459fcbeb1de0449aab50670f1bf7a44afd3 (diff)
downloadslskd-6eac4a56dfd2a9c7729f63b3de329480253b5656.tar.gz
add TryDispose
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>