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

Commit 11f487f

Browse files
committed
Change behavior of .NET Core GetGenericArguments() to match behavior in .NET fx
1 parent 87f322e commit 11f487f

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/ServiceStack.Text/PlatformExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static Type[] GetTypeGenericArguments(this Type type)
117117
public static ConstructorInfo GetEmptyConstructor(this Type type)
118118
{
119119
#if (NETFX_CORE || PCL || NETSTANDARD1_1)
120-
return type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(c => c.GetParameters().Count() == 0);
120+
return type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(c => c.GetParameters().Length == 0);
121121
#else
122122
return type.GetConstructor(Type.EmptyTypes);
123123
#endif

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public static class ReflectionExtensions
7878

7979
public static Type[] GetGenericArguments(this Type type)
8080
{
81-
return type.GetTypeInfo().GenericTypeArguments;
81+
//http://stackoverflow.com/a/39140220/85785
82+
return type.GetTypeInfo().IsGenericTypeDefinition
83+
? type.GetTypeInfo().GenericTypeParameters
84+
: type.GetTypeInfo().GenericTypeArguments;
8285
}
8386

8487
internal static TypeInfo GetTypeInfo(this Type type)

tests/NetCore.Console.Tests/project.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
"frameworks": {
1515
"netcoreapp1.1": {
1616
"dependencies": {
17-
"Microsoft.NETCore.App": {
18-
"type": "platform",
19-
"version": "1.0.1"
20-
}
2117
},
2218
"imports": [
2319
"dotnet5.6",

0 commit comments

Comments
 (0)