From 9557f842cc68eb259eacbe15d33ce09ad04dba08 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 30 Jan 2022 13:18:39 -0600 Subject: add IsDictionary --- src/slskd/Common/Extensions.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') 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; @@ -307,6 +308,23 @@ namespace slskd return builder.ToString(); } + /// + /// Determines whether the given object is a . + /// + /// The object to check. + /// A value indicating whether the given object is a dictionary. + 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<,>)); + } + /// /// Redacts this instance of Options, replacing properties marked with with '*****'. /// -- cgit v1.2.3