提供这样的代码:
switch (args[0])
{
case "foo":
{
var operation = new FooOperation();
operation.Do();
break;
}
case "bar":
{
var operation = new BarOperation();
operation.Do();
break;
}
default: throw new Exception();
}
我想从交换机中拉出公共部分,如下所示:
IOperation operation;
switch (args[0])
{
case "foo":
{
operation = new FooOperation();
break;
}
case "bar":
{
operation = new BarOperation();
break;
}
default: throw new Exception();
}
operation.Do();
我想在不打字的情况下这样做 - 只需要ReSharper转换。有没有办法做到这一点?
(有关合法和编译的完整计划,请参阅https://gist.github.com/JayBazuzi/2457e8389d338688a9ab和https://gist.github.com/JayBazuzi/798bdca40d59e095e83b)