开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜