mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model - Fixed IEnumerable detection for strings and... IEnumerables
This commit is contained in:
parent
1b46ef4f81
commit
ef62e30c6f
@ -100,6 +100,13 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool IsGenericEnumerable(this Type type)
|
public static bool IsGenericEnumerable(this Type type)
|
||||||
{
|
{
|
||||||
|
// String is an IEnumerable to be fair, but not for us
|
||||||
|
if (type == typeof(string))
|
||||||
|
return false;
|
||||||
|
// It may actually be one instead of implementing one ;)
|
||||||
|
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
|
||||||
|
return true;
|
||||||
|
|
||||||
return type.GetInterfaces().Any(x =>
|
return type.GetInterfaces().Any(x =>
|
||||||
x.IsGenericType &&
|
x.IsGenericType &&
|
||||||
x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
|
x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
|
||||||
@ -110,6 +117,10 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static Type? GetGenericEnumerableType(this Type type)
|
public static Type? GetGenericEnumerableType(this Type type)
|
||||||
{
|
{
|
||||||
|
// It may actually be one instead of implementing one ;)
|
||||||
|
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
|
||||||
|
return type.GenericTypeArguments[0];
|
||||||
|
|
||||||
Type enumerableType = type.GetInterfaces().FirstOrDefault(x =>
|
Type enumerableType = type.GetInterfaces().FirstOrDefault(x =>
|
||||||
x.IsGenericType &&
|
x.IsGenericType &&
|
||||||
x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
|
x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user