mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 20:13:40 +00:00
Fix deserializing of Emoji types (#2577)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user