【问题标题】:GetType from fully qualified type name not working来自完全限定类型名称的 GetType 不起作用
【发布时间】:2016-04-21 11:18:44
【问题描述】:
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

【问题讨论】:

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


    【解决方案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的副本

    【讨论】:

    • 嗯,出于某种原因,我认为 CreateInstance 使用 FQTN 会有所不同。不知道为什么我会这么想。
    猜你喜欢
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    相关资源
    最近更新 更多