Skip to content

Instantly share code, notes, and snippets.


gdyrrahitis/MainForm.cs Secret

Created Nov 10, 2018
What would you like to do?
private ICommand GetCommand(int x, int y)
// Using pattern matching to find shape and create the command
switch (_activeShape)
case var square when square == typeof(Square):
return new DrawSquareCommand(_bitmap, new Square(100, 100), new Point(x, y));
case var rectangle when rectangle == typeof(Rect):
return new DrawRectangleCommand(_bitmap, new Rect(100, 50), new Point(x, y));
case var triangle when triangle == typeof(Triangle):
return new DrawTriangleCommand(_bitmap, new Triangle(70, 35), new Point(x, y));
throw new ArgumentOutOfRangeException("Cannot recognize shape.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment