Ok, here is a funky helper method to give you a flexible way to activate a type with a given array of parameters:
static object GetInstanceFromParameters(Assembly a, string typeName, params object[] pars) { var t = a.GetType(typeName); var c = t.GetConstructor(pars.Select(p => p.GetType()).ToArray()); if (c == null) return null; return c.Invoke(pars); }
And you call it like this:
Foo f = GetInstanceFromParameters(a, "SmartDeviceProject1.Foo", "hello", 17) as Foo;
So, you pass the assembly and the type name as the first two parameters, and then all the constructor parameters are fine.
Matt hamilton
source share