From 78a3b73cf6309ff1377af25be0afdebad30cc556 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Fri, 4 Dec 2020 23:42:47 -0500 Subject: [PATCH] optionally allow us to FindType with using namespaces --- MBS.Framework/Reflection.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MBS.Framework/Reflection.cs b/MBS.Framework/Reflection.cs index da3fe2f..163ec7e 100644 --- a/MBS.Framework/Reflection.cs +++ b/MBS.Framework/Reflection.cs @@ -42,7 +42,7 @@ namespace MBS.Framework private static Dictionary TypesByName = new Dictionary(); - public static Type FindType(string TypeName) + public static Type FindType(string TypeName, string[] usingNamespaces = null) { // first try using System.Type own GetType() method Type type = Type.GetType(TypeName); @@ -79,7 +79,19 @@ namespace MBS.Framework } if (found) break; } - if (!found) return null; + if (!found) + { + if (usingNamespaces != null) + { + for (int i = 0; i < usingNamespaces.Length; i++) + { + Type t = FindType(String.Format("{0}.{1}", usingNamespaces[i], TypeName)); + if (t != null) + return t; + } + } + return null; + } } return TypesByName[TypeName]; }