jeudi 5 mars 2015

C# - Using Activator.CreateInstance to call internal constructor with parameters

I am using the Activator's CreateInstance method to dynamically create objects with internal constructors from a factory in the same Assembly. This works great when I need to call a parameterless internal constructor using the Activator.CreateInstance(Type type, bool nonPublic) overoad. This also works when I call a public constructor with parameters by using the CreateInstance(Type type, params Object[]) overload. However, if I am stumped on how to call a constructor that is both public and has parameters. I cannot find an overloaded CreateInstance method that takes both a nonPublic flag and any a list of parameters. This functionality seems pretty basic, so I am probably missing something obvious. Any help would be much appreciated!






Aucun commentaire:

Enregistrer un commentaire