-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deserializing of Emoji types (#2577)
- Loading branch information
1 parent
3c05db4
commit 2701be5
Showing
4 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters