Redo method using Activator.CreateInstance

how might I redo this method with 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 

Answers


The most literal response is something like this:

Dim t As Type = GetType(Foo) 'Get Foo from somewhere
Dim ctorArgs() New As Object { Me }
Return (CreditType)Activator.CreateInstance(t, ctorArgs)

Need Your Help

Copy an outlook email to a folder or read the email via javamail?

java email outlook

We are handling many emails from our clients. Each email that has a subject line with a case number is uploaded to our CRM. Currently we have our analyst doing this process, ie., every email he get...

Extracting data from a database into array

php mysql json mysqli

I'm building an angular application, so I have a PHP script extracting the database data into a JSON when requested.