Created
December 6, 2014 22:20
-
-
Save JayBazuzi/2457e8389d338688a9ab to your computer and use it in GitHub Desktop.
Sample code for https://stackoverflow.com/questions/27336390/can-i-extract-common-code-from-switch-cases-with-only-resharper-transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
switch (args[0]) | |
{ | |
case "foo": | |
{ | |
IOperation operation = new FooOperation(); | |
operation.Do(); | |
break; | |
} | |
case "bar": | |
{ | |
IOperation operation = new BarOperation(); | |
operation.Do(); | |
break; | |
} | |
case "baz": | |
{ | |
IOperation operation = new BazOperation(); | |
operation.Do(); | |
break; | |
} | |
default: | |
throw new System.Exception(); | |
} | |
} | |
} | |
class BazOperation : IOperation | |
{ | |
public void Do() | |
{ | |
} | |
} | |
class FooOperation : IOperation | |
{ | |
public void Do() | |
{ | |
} | |
} | |
class BarOperation : IOperation | |
{ | |
public void Do() | |
{ | |
} | |
} | |
interface IOperation | |
{ | |
void Do(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment