The method Type.GetType(string typeName)
does what you want, but if you only provide the FullName
(namespace and name) of the type, it will only resolve types from the current assembly or mscorlib.
You would need to supply an AssemblyQualifiedName
if you want to resolve types outside the current assembly. The problem of course is that multiple assemblies can contain different types with the same name and namespace (thanks Steven Liekens):
string aqn = Assembly.CreateQualifiedName(assemblyName, namespaceAndNameOfType);
Type t = Type.GetType(aqn);
If you don't know the assembly beforehand, you could deal with this by:
- Loading all assemblies from the current
AppDomain.BaseDirectory
, or - Using
AppDomain.GetAssemblies()
for the currently loaded assemblies
And then iterating over each assembly's GetTypes()
method.