I define an collection initializer with IEnumerable as instructed here: http://msdn.microsoft.com/en-us/library/bb384062.aspx
Now I\'m able to create objects within
I don't recommend in this case, but it's possible to use multiple Add overloads.
So in ArrangedPannel include
public void Add(int padding)
{
Padding = padding;
}
Then can defined in code like
debugPanel.Add(new ArrangedPanel()
{
5, // is this Padding?
new ButtonToggle(),
new ButtonToggle()
});
But I prefer @Haymo's answer because here it's not clear what '5' is set to, and multiple int properties will probably lead to crazy code like
public void Add(int intProp)
{
var current = intPropSetCount++;
switch(current)
{
case 0: Padding = intProp; return;
case 1: SecondProp = intProp; return;
// ...
default: throw new Exception();
}
}
This idea is probably best left for combining multiple collections into 1 wrapper.