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

Commit 55c2780

Browse files
committed
Add GetCollectionType looking at array element type or generic arg of collection type
1 parent f79c0d6 commit 55c2780

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,20 @@ public static Delegate CreateDelegate(this MethodInfo methodInfo, Type delegateT
16641664
return Delegate.CreateDelegate(delegateType, target, methodInfo);
16651665
#endif
16661666
}
1667+
1668+
public static Type ElementType(this Type type)
1669+
{
1670+
#if PCL
1671+
return type.GetTypeInfo().GetElementType();
1672+
#else
1673+
return type.GetElementType();
1674+
#endif
1675+
}
1676+
1677+
public static Type GetCollectionType(this Type type)
1678+
{
1679+
return type.ElementType() ?? type.GetTypeGenericArguments().FirstOrDefault();
1680+
}
16671681
}
16681682

16691683
}

0 commit comments

Comments
 (0)