在.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