optionally allow us to FindType with using namespaces

This commit is contained in:
Michael Becker 2020-12-04 23:42:47 -05:00
parent 080a5c0f2d
commit 78a3b73cf6
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7

View File

@ -42,7 +42,7 @@ namespace MBS.Framework
private static Dictionary<string, Type> TypesByName = new Dictionary<string, Type>();
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];
}