在.NET中将字符串转换为Type对象的最佳方式是什么?从.NET中的字符串获取Type对象的最佳方式
要考虑的问题:
- 的类型可以是在一个不同的组件。
- 该类型的程序集可能尚未加载。
这是我的尝试,但它并没有解决第二个问题
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
解决第二种情况很困难。一般如何知道卸载的组件所在的位置?否则看到[这个答案](http://stackoverflow.com/a/7286354/661933),相当不错。 – nawfal 2013-12-05 19:44:48