Fix deserializing of Emoji types (#2577)

This commit is contained in:
Chris Simpson
2022-09-20 21:15:19 +01:00
committed by GitHub
parent 3c05db4065
commit 2701be5e79
4 changed files with 54 additions and 11 deletions
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Linq;
namespace Octokit
{
public static class AssignableExtensions
{
/// <summary>
/// Determines whether the <paramref name="genericType"/> is assignable from
/// <paramref name="givenType"/> taking into account generic definitions
/// </summary>
public static bool IsAssignableToGenericType(this Type givenType, Type genericType)
{
if (givenType == null || genericType == null)
{
return false;
}
return givenType == genericType
|| givenType.MapsToGenericTypeDefinition(genericType)
|| givenType.HasInterfaceThatMapsToGenericTypeDefinition(genericType)
|| givenType.BaseType.IsAssignableToGenericType(genericType);
}
private static bool HasInterfaceThatMapsToGenericTypeDefinition(this Type givenType, Type genericType)
{
return givenType
.GetInterfaces()
.Where(it => it.IsGenericType)
.Any(it => it.GetGenericTypeDefinition() == genericType);
}
private static bool MapsToGenericTypeDefinition(this Type givenType, Type genericType)
{
return genericType.IsGenericTypeDefinition
&& givenType.IsGenericType
&& givenType.GetGenericTypeDefinition() == genericType;
}
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ namespace Octokit.Internal
// simple json does not support the root node being empty. Will submit a pr but in the mean time....
if (!string.IsNullOrEmpty(body) && body != "{}")
{
var typeIsDictionary = typeof(IDictionary).IsAssignableFrom(typeof(T));
var typeIsDictionary = typeof(IDictionary).IsAssignableFrom(typeof(T)) || typeof(T).IsAssignableToGenericType(typeof(System.Collections.Generic.IDictionary<,>));
var typeIsEnumerable = typeof(IEnumerable).IsAssignableFrom(typeof(T));
var responseIsObject = body.StartsWith("{", StringComparison.Ordinal);