|
6 | 6 | using System.Collections.Generic; |
7 | 7 | using System.Diagnostics.Contracts; |
8 | 8 | using System.Linq; |
| 9 | +#if NETSTANDARD1_4 |
| 10 | +using System.Reflection; |
| 11 | +#endif |
9 | 12 | using System.Runtime.CompilerServices; |
10 | 13 |
|
11 | 14 | #nullable enable |
@@ -62,7 +65,12 @@ static string FormatDisplayString(Type type) |
62 | 65 | } |
63 | 66 |
|
64 | 67 | // Generic types |
65 | | - if (type.IsGenericType && |
| 68 | + if ( |
| 69 | +#if NETSTANDARD1_4 |
| 70 | + type.GetTypeInfo().IsGenericType && |
| 71 | +#else |
| 72 | + type.IsGenericType && |
| 73 | +#endif |
66 | 74 | type.FullName is { } fullName && |
67 | 75 | fullName.Split('`') is { } tokens && |
68 | 76 | tokens.Length > 0 && |
@@ -113,5 +121,28 @@ tokens[0] is { } genericName && |
113 | 121 | // be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835. |
114 | 122 | return DisplayNames.GetValue(type, t => FormatDisplayString(t)); |
115 | 123 | } |
| 124 | + |
| 125 | +#if NETSTANDARD1_4 |
| 126 | + /// <summary> |
| 127 | + /// Returns an array of types representing the generic arguments. |
| 128 | + /// </summary> |
| 129 | + /// <param name="type">The input type.</param> |
| 130 | + /// <returns>An array of types representing the generic arguments.</returns> |
| 131 | + private static Type[] GetGenericArguments(this Type type) |
| 132 | + { |
| 133 | + return type.GetTypeInfo().GenericTypeParameters; |
| 134 | + } |
| 135 | + |
| 136 | + /// <summary> |
| 137 | + /// Returns whether <paramref name="type"/> is an instance of <paramref name="value"/>. |
| 138 | + /// </summary> |
| 139 | + /// <param name="type">The input type.</param> |
| 140 | + /// <param name="value">The type to check against.</param> |
| 141 | + /// <returns><see langword="true"/> if <paramref name="type"/> is an instance of <paramref name="value"/>, <see langword="false"/> otherwise.</returns> |
| 142 | + internal static bool IsInstanceOfType(this Type type, object value) |
| 143 | + { |
| 144 | + return type.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()); |
| 145 | + } |
| 146 | +#endif |
116 | 147 | } |
117 | 148 | } |
0 commit comments