refactor(UXAssist): harden ModFeatureRegistry

This commit is contained in:
2026-06-23 02:23:20 +08:00
parent cb7a965d12
commit 91259bbd17
4 changed files with 128 additions and 20 deletions
+14 -2
View File
@@ -8,16 +8,28 @@ namespace UXAssist.Common;
public static class Util
{
/// <summary>
/// Returns all types from the assembly matching the predicate, tolerating partially loadable assemblies.
/// </summary>
public static Type[] GetTypesFiltered(Assembly assembly, Func<Type, bool> predicate)
{
return [.. assembly.GetTypes().Where(predicate)];
try
{
return [.. assembly.GetTypes().Where(predicate)];
}
catch (ReflectionTypeLoadException ex)
{
return [.. ex.Types.Where(t => t != null).Where(predicate)];
}
}
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) => GetTypesFiltered(assembly, t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal));
public static Type[] GetTypesInNamespacePrefix(Assembly assembly, string prefix)
{
return GetTypesFiltered(assembly, t => t.Namespace != null && t.Namespace.StartsWith(prefix, StringComparison.Ordinal));
return GetTypesFiltered(assembly, t =>
t.Namespace != null &&
(t.Namespace == prefix || t.Namespace.StartsWith(prefix + ".", StringComparison.Ordinal)));
}
public static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)