From a41916d97f65057937b1cea64de5ae4d4f16fc49 Mon Sep 17 00:00:00 2001 From: uurha Date: Mon, 10 Apr 2023 17:37:01 +0000 Subject: [PATCH] Merge pull request #33 from uurha/dev Add GetAllInheritedType --- Runtime/Extension/ReflectionExtensions.cs | 18 ++++++++++++++++++ package.json | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Runtime/Extension/ReflectionExtensions.cs b/Runtime/Extension/ReflectionExtensions.cs index ecbbf61..afdc03b 100644 --- a/Runtime/Extension/ReflectionExtensions.cs +++ b/Runtime/Extension/ReflectionExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Better.Extensions.Runtime @@ -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) { diff --git a/package.json b/package.json index f7fb8cf..36d1502 100644 --- a/package.json +++ b/package.json @@ -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",