完全限定类型名称的GetType不起作用

时间:2016-01-15 19:20:15

标签: vb.net types fully-qualified-naming

Public Sub New(ByVal oldC As Control)
    Dim FQTN As String = oldC.GetType.FullName
    Dim t As Type = Type.GetType(FQTN)
    Dim newC As Object = Activator.CreateInstance(t)
End Sub

FQTN返回正确的类型名称,但tNothing。例如,FQTN = System.Windows.Forms.Panel

1 个答案:

答案 0 :(得分:1)

摆脱FQTN

这适用于您正在寻找

的面板示例
Public Sub New(ByVal oldC As Control)
    Dim t As Type = oldC.GetType()
    Dim newC As Object = Activator.CreateInstance(t)
End Sub

此外,这是Type.GetType("namespace.a.b.ClassName") returns null

的副本