我可以仅使用ReSharper转换从`switch`案例中提取公共代码吗?

时间:2014-12-06 20:53:19

标签: c# resharper

提供这样的代码:

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/2457e8389d338688a9abhttps://gist.github.com/JayBazuzi/798bdca40d59e095e83b

0 个答案:

没有答案