How to call the non Default constructor with assembly.CreateInstance
I need to call the Non default constructo开发者_C百科r when using assembly.CreateInstance. how?
Activator.CreateInstance
is a much friendlier API than Assembly.CreateInstance
to use for these kinds of things:
var type = Type.GetType("MyNamespace.MyClass, MyAssembly");
Activator.CreateInstance(type, constructorParam1, constructorParam2);
Try this overload:
public Object CreateInstance (
string typeName,
bool ignoreCase,
BindingFlags bindingAttr,
Binder binder,
Object[] args,
CultureInfo culture,
Object[] activationAttributes
)
It has an args
paramter.
精彩评论