The method activator.CreateInstance() is known to be slow. Direct calling var X = new Class() is the quickest. But Expression.New() compiled is also very quick.
But I don't know how to let it work with a variable number of params in the constructor.
So my question is: how should I create a func<Type, object[], object> with expressions to create an instance, where the object array contains the parameters for the constructor.
The end goal is to do this:
var a = Creator(typeof(ClassA),new[]{1,2}); //ClassA has 2 params
var b = Creator(typeof(ClassB),new[]{"some text"}); //ClassB has only 1 param
I have read in the Expression.New() there is a possibility to have multiple params.
The above question in a comment can bring some light too, but regarding
Expression.Newand parameters: