- enum Color { Red, Green, Blue }
- static class ColorExtensions {
- public static T Switch<T> (this Color color, T Red, T Green, T Blue) {
- switch (color) {
- case Color.Red: return Red;
- case Color.Blue: return Blue;
- case Color.Green: return Green;
- default:
- throw new Exception ("Inexhaustive switch");
- }
- }
- }
- public int GetRGBComponent (int hex, Color color) {
- return hex >> color.Switch (Red: 16, Green: 8, Blue: 0) & 0xFF;
- }