In C# can I pass a delegate an argument list for a class constructor in a fairly concise way?
I know this is extremely situational and may seem a bit of an odd request, also it's not for the factory pattern. If it helps think of it as a challenge. The correct answer to this question may be that it is not possible.
Func<MyClassConstructionArgsType, MyClass> make_MyClass =
args => {return new MyClass(args);};
var n = make_MyClass(comma separated arguments);
I also need there to not be a copy of the description of what the arguments are, the below for example is not a solution:
Func<int, string, MyClass> make_MyClass =
(a, b) => {return new MyClass(a, b);};
Or, for the same reasons this:
Class Args
{
...
}
Func<Args, MyClass> make_MyClass =
a => {return new MyClass(a);};
var n = make_MyClass(Args(args));
Dito where this is the case:
var n = make_MyClass<MyClass>(comma separated arguments);
The Object[]{comma separated arguments} approach is good except that optional parameters also need to be supported.
This question was created as a result of Anastasiosyal's answer from the following question: c# class reference as opposed to instance reference
Josh first answer seems as close as is possible in C#.