Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
uurha authored Mar 3, 2024
2 parents 8a57b98 + cc3e29e commit f68ed0c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 35 additions & 1 deletion Assets/BetterExtensions/Runtime/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,41 @@ public static bool IsEnumerable(this Type self)
}

var enumerableType = typeof(IEnumerable<>);
return self.IsSubclassOfRawGeneric(enumerableType);
return enumerableType.IsAssignableFromRawGeneric(self);
}

public static bool IsAssignableFromRawGeneric(this Type self, Type type)
{
if (self == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(self));
return false;
}

if (type == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(type));
return false;
}

var bufferType = type;
while (bufferType.BaseType != null)
{
if (bufferType.IsGeneric(self))
{
return true;
}

foreach (var subType in bufferType.GetInterfaces())
{
if (!subType.IsGeneric(self)) continue;
return true;
}

bufferType = bufferType.BaseType;
}

return false;
}

public static bool IsGeneric(this Type self, Type type)
Expand Down
2 changes: 1 addition & 1 deletion Assets/BetterExtensions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.uurha.betterextensions",
"displayName": "Better Extensions",
"version": "1.5.9",
"version": "1.5.91",
"unity": "2021.3",
"description": "Unity extensions, serialize extension, async extension, string extension and UI extensions",
"dependencies": {
Expand Down

0 comments on commit f68ed0c

Please sign in to comment.