Sub创建VB.NET中调用者传递的类型对象

Mic*_*ael 8 vb.net

我在创建一个可以动态创建变量类型对象的子项时遇到了麻烦.这是我想要实现的一个例子:

class systemSettings
    'some properties
end class

Class fireSystemSettings
    inherits systemSettings
    'some additional properties
end class

Class windSystemSettings
    inherits systemSettings
    'some additional properties
end class

sub createSystem(systemType as Type, arg1 as object, arg2 as object)
    Dim newSystem as New systemType(arg1, arg2)
    systemCollection.add(newSystem)
end sub
Run Code Online (Sandbox Code Playgroud)

我无法让它发挥作用.我做了一些研究,看了泛型类型,反射和其他工具,但我无法确定如何最好地解决这个问题.

SLa*_*aks 8

您正在寻找 Activator.CreateInstance(systemType)