(The question might not make enough sense. It was hard to write it. Feel free to update it if you can make it more clear.)
I have an enum:
public enum nodeTypes
{
Part = 1,
SelectListValue,
MultiSelectListValue,
RepeatingPart,
...
}
And a method with a switch case:
switch (type)
{
case nodeTypes.SelectListValue:
GenerateSubNode<SelectListValue>(parent, root, depth, true);
break;
case nodeTypes.MultiSelectListValue:
GenerateSubNode<MultiSelectListValue>(parent, root, depth, true);
break;
case nodeTypes.Part:
GenerateSubNode<Part>(parent, root, depth, true);
break;
case ....
}
And another method:
private void GenerateSubNode<ComponentType>(Container parent, ZForm root, int depth, bool isContainer) where ComponentType : Component, new()
{
...
var c = new ComponentType();
...
}
Is there a way to write that switch case statement as a 1 liner? It feels like repetitive code.