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

Commit b35804b

Browse files
committed
Add optional defaultValue to Get<T>
1 parent 9034f7c commit b35804b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ServiceStack.Text/JsonObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static T JsonTo<T>(this Dictionary<string, string> map, string key)
1616
/// <summary>
1717
/// Get JSON string value converted to T
1818
/// </summary>
19-
public static T Get<T>(this Dictionary<string, string> map, string key)
19+
public static T Get<T>(this Dictionary<string, string> map, string key, T defaultValue = default(T))
2020
{
2121
string strVal;
22-
return map.TryGetValue(key, out strVal) ? JsonSerializer.DeserializeFromString<T>(strVal) : default(T);
22+
return map.TryGetValue(key, out strVal) ? JsonSerializer.DeserializeFromString<T>(strVal) : defaultValue;
2323
}
2424

2525
public static T[] GetArray<T>(this Dictionary<string, string> map, string key)

0 commit comments

Comments
 (0)