What is the best way to convert a string into a Type object in .NET?
Issues to consider:
This is my attempt, but it doesn't address the second issue
Public Function FindType(ByVal name As String) As Type
Dim base As Type
base = Reflection.Assembly.GetEntryAssembly.GetType(name, False, True)
If base IsNot Nothing Then Return base
base = Reflection.Assembly.GetExecutingAssembly.GetType(name, False, True)
If base IsNot Nothing Then Return base
For Each assembly As Reflection.Assembly In _
AppDomain.CurrentDomain.GetAssemblies
base = assembly.GetType(name, False, True)
If base IsNot Nothing Then Return base
Next
Return Nothing
End Function
You can use Type.GetType(string) in order to do this. The type name must be assembly qualified but the method will load the assembly as necessary. The assembly qualification is not necessary if the type is in mscorlid or the assembly which executes the GetType call.