如何使用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 发布于 2012-06-08 03:42:41
最直白的回答是这样的:
Dim t As Type = GetType(Foo) 'Get Foo from somewhere
Dim ctorArgs() New As Object { Me }
Return (CreditType)Activator.CreateInstance(t, ctorArgs)https://stackoverflow.com/questions/10935315
复制相似问题