C# multiple arguments in one to DRY out parameter-passing
arguments, c#, parameters, syntactic-sugar
Solution
I mean, there's this:
Func<Thing> f = () => new Thing(arg1, arg2, arg3, arg4);
Thing thing1 = f();
Thing thing2 = f();
Thing thing3 = f();
Thing thing4 = f();
Just be careful of closure semantics.
Problem
I don't know if this is possible, but in some of my unit tests, I end up initializing different objects with the same arguments. I would like to be able to store those arguments in some variable and just initialize the multi-parameter object constructor with that variable so instead of doing: ``` Thing thing1 = new Thing(arg1, arg2, arg3, arg4); Thing thing2 = new Thing(arg1, arg2, arg3, arg4); Thing thing3 = new Thing(arg1, arg2, arg3, arg4); ``` I could do the following: ``` MagicalArgumentsContainer args = (arg1, arg2, arg3, arg4); Thing thing1 = new Thing(args); Thing thing2 = new Thing(args); Thing thing3 = new Thing(args); ``` Is there any way of doing this without overriding `Thing`'s constructor to take a list that it manually explodes and plucks arguments out of? Maybe some C# syntactic sugar?