Consider this code:
switch(formatindex)
{
case 0:
var myExporter = new PngExporter { Background = OxyColors.Black };
fileExtension = ".jpg";
case 1:
var myExporter = new SvgExporter();
fileExtension = ".svg";
}
Of course this won't compile, since I declare myExporter twice.
The question is, is there a neat way to choose the type/constructor based on the switch-case outcome.
In my case (which caused this question), the rest of the code using myExporteris the same no matter which type is chosen, because only properties that are used are width and height and these all behave the same way with both types of exporters.
I don't want to write the subsequent code twice, which is why I thought I could do something similar to the shown code.