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 #33 from uurha/dev
Browse files Browse the repository at this point in the history
Add GetAllInheritedType
  • Loading branch information
uurha committed Apr 10, 2023
1 parent 17a9bf4 commit a41916d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Runtime/Extension/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Better.Extensions.Runtime
Expand All @@ -20,6 +21,23 @@ public static bool IsArrayOrList(this Type listType)

return false;
}

public static Type[] GetAllInheritedType(Type baseType)
{
return AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => ArgIsValueType(baseType, p)).ToArray();
}

private static bool ArgIsValueType(Type baseType, Type iterateValue)
{
return CheckType(baseType, iterateValue) &&
(iterateValue.IsClass || iterateValue.IsValueType) &&
!iterateValue.IsAbstract && !iterateValue.IsSubclassOf(typeof(UnityEngine.Object));
}

private static bool CheckType(Type baseType, Type p)
{
return baseType.IsAssignableFrom(p);
}

public static Type GetArrayOrListElementType(this Type listType)
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.uurha.betterextensions",
"displayName": "Better Extensions",
"description": "Unity extensions, serialize extension, async extension, string extension and UI extensions",
"version": "0.3.5",
"version": "1.0.0",
"unity": "2018.3",
"author": {
"name": "Arcueid D'athemon",
Expand Down

0 comments on commit a41916d

Please sign in to comment.