0

我怎么能用 Activator.CreateInstance 重做这个方法

    Public Overridable Function setCreditType() As CreditType 
    Select Case creditTypeId 
        Case Is = 0 
            Return New NewCredit(Me) 
        Case Is = 1 
            Return New ExecutiveProducer(Me) 
        Case Is = 2 
            Return New Producer(Me) 
        Case Else 
            Return New NullCredit(Me) 
    End Select 
End Function 
4

1 回答 1

0

最直接的回应是这样的:

Dim t As Type = GetType(Foo) 'Get Foo from somewhere
Dim ctorArgs() New As Object { Me }
Return (CreditType)Activator.CreateInstance(t, ctorArgs)
于 2012-06-07T19:42:40.900 回答