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

Commit 00c6f4b

Browse files
author
Wim Pool
committed
Generics null check and ICollection added
null check for GetTypeWithGenericsInterfaceOf(typeof(IEnumerable<>) and make ICollection behave the same as IEnumerable
1 parent 9cb0a0a commit 00c6f4b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ServiceStack.Text/Common/DeserializeSpecializedCollections.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static ParseStringDelegate GetParseFn()
5252
return ParseStringCollection<TSerializer>;
5353
}
5454
#endif
55-
if (typeof(T) == typeof(IEnumerable))
55+
if (typeof (T) == typeof (IEnumerable) || typeof(T) == typeof(ICollection))
5656
{
57-
return GetEnumerableParseFn();
57+
GetEnumerableParseFn();
5858
}
5959

6060
return GetGenericEnumerableParseFn();
@@ -139,6 +139,7 @@ public static ParseStringDelegate GetEnumerableParseFn()
139139
public static ParseStringDelegate GetGenericEnumerableParseFn()
140140
{
141141
var enumerableInterface = typeof(T).GetTypeWithGenericInterfaceOf(typeof(IEnumerable<>));
142+
if (enumerableInterface == null) return null;
142143
var elementType = enumerableInterface.GenericTypeArguments()[0];
143144
var genericType = typeof(SpecializedEnumerableElements<,>).MakeGenericType(typeof(T), elementType);
144145
var fi = genericType.GetPublicStaticField("ConvertFn");
@@ -213,4 +214,4 @@ public static object ConvertFromCollection(object enumerable)
213214
return to;
214215
}
215216
}
216-
}
217+
}

0 commit comments

Comments
 (0)