diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-30 12:40:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-30 12:40:00 -0500 |
| commit | 8624a5387b6db17141fa6bb7601b1490c1f95c30 (patch) | |
| tree | b2264599945ff634f25286c485ee2848db7287e8 /src/slskd/Common/CommonExtensions.cs | |
| parent | 915ed6aa255636cfd339e9b53b4da202a3799f98 (diff) | |
| parent | dbe3a9e82036a0db8049f3b884342dc98cc98d58 (diff) | |
| download | slskd-8624a5387b6db17141fa6bb7601b1490c1f95c30.tar.gz | |
Merge branch 'master' into secret-gen
Diffstat (limited to 'src/slskd/Common/CommonExtensions.cs')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 16 |
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> |
