What is the best way to convert a string to a Type object in .NET?
Questions to consider:
- The type may be in a different assembly.
- The type node is not yet loaded.
This is my attempt, but it does not address the second problem.
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
Jonathan allen
source share