From c20f210b292a9792b407b37d9e1c9f21a654887a Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 27 Apr 2025 22:28:21 +0300 Subject: [PATCH] refactor: rewritten GetType in a more readable way --- Engine.Core/Factory/TypeFactory.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Engine.Core/Factory/TypeFactory.cs b/Engine.Core/Factory/TypeFactory.cs index 54629c0..e7a653d 100644 --- a/Engine.Core/Factory/TypeFactory.cs +++ b/Engine.Core/Factory/TypeFactory.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Reflection; namespace Syntriax.Engine.Core.Factory; @@ -24,11 +23,9 @@ public static class TypeFactory } public static Type GetType(string fullName) - { - foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) - if (assembly.GetTypes().FirstOrDefault(t => t.FullName?.CompareTo(fullName) == 0) is Type type) - return type; - - throw new Exception($"Type {fullName} could not be found in the current domain."); - } + => AppDomain.CurrentDomain + .GetAssemblies() + .SelectMany(a => a.GetTypes()) + .FirstOrDefault(t => t.FullName?.CompareTo(fullName) == 0) + ?? throw new Exception($"Type {fullName} could not be found in the current domain."); }