Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 70f8e50

Browse files
committed
update ToStringDictionary() to support KVPs and string dictionary
1 parent 635cfb3 commit 70f8e50

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/ServiceStack.Text/TypeSerializer.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,26 @@ public static Dictionary<string, string> ToStringDictionary(this object obj)
208208
{
209209
if (obj == null)
210210
return new Dictionary<string, string>();
211-
212-
if (obj is Dictionary<string, object> objDictionary)
211+
212+
if (obj is Dictionary<string, string> strDictionary)
213+
return strDictionary;
214+
215+
if (obj is IEnumerable<KeyValuePair<string, string>> kvpStrings)
216+
{
217+
var to = new Dictionary<string, string>();
218+
foreach (var kvp in kvpStrings)
219+
{
220+
to[kvp.Key] = kvp.Value;
221+
}
222+
return to;
223+
}
224+
225+
if (obj is IEnumerable<KeyValuePair<string, object>> kvps)
213226
{
214-
var to = new Dictionary<string,string>();
215-
foreach (var entry in objDictionary)
227+
var to = new Dictionary<string, string>();
228+
foreach (var kvp in kvps)
216229
{
217-
to[entry.Key] = entry.Value?.ToString();
230+
to[kvp.Key] = kvp.Value?.ToString();
218231
}
219232
return to;
220233
}

0 commit comments

Comments
 (0)