diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-01-30 13:18:39 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-01-30 13:18:39 -0600 |
| commit | 9557f842cc68eb259eacbe15d33ce09ad04dba08 (patch) | |
| tree | 28d5426494194b656c8b0bccd35e98f25bb658d1 | |
| parent | 24dc05d101691e7c3216eca767d329af795c0036 (diff) | |
| download | slskd-9557f842cc68eb259eacbe15d33ce09ad04dba08.tar.gz | |
add IsDictionary
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 90f0b659..ebf16fce 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -18,6 +18,7 @@ namespace slskd { using System; + using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -308,6 +309,23 @@ namespace slskd } /// <summary> + /// Determines whether the given object is a <see cref="Dictionary{TKey, TValue}"/>. + /// </summary> + /// <param name="obj">The object to check.</param> + /// <returns>A value indicating whether the given object is a dictionary.</returns> + public static bool IsDictionary(this object obj) + { + if (obj == null) + { + return false; + } + + return obj is IDictionary && + obj.GetType().IsGenericType && + obj.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<,>)); + } + + /// <summary> /// Redacts this instance of Options, replacing properties marked with <see cref="SecretAttribute"/> with '*****'. /// </summary> /// <remarks> |
