Created
December 6, 2014 22:19
-
-
Save JayBazuzi/798bdca40d59e095e83b 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) | |
{ | |
IOperation operation; | |
switch (args[0]) | |
{ | |
case "foo": | |
{ | |
operation = new FooOperation(); | |
break; | |
} | |
case "bar": | |
{ | |
operation = new BarOperation(); | |
break; | |
} | |
case "baz": | |
{ | |
operation = new BazOperation(); | |
break; | |
} | |
default: | |
throw new System.Exception(); | |
} | |
operation.Do(); | |
} | |
} | |
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