1. enum Color { Red, Green, Blue }
  2. static class ColorExtensions {
  3. public static T Switch<T> (this Color color, T Red, T Green, T Blue) {
  4. switch (color) {
  5. case Color.Red: return Red;
  6. case Color.Blue: return Blue;
  7. case Color.Green: return Green;
  8. default:
  9. throw new Exception ("Inexhaustive switch");
  10. }
  11. }
  12. }
  13. public int GetRGBComponent (int hex, Color color) {
  14. return hex >> color.Switch (Red: 16, Green: 8, Blue: 0) & 0xFF;
  15. }
Comments powered by Disqus