EnumHelper.cs 320 B

12345678910111213141516171819202122
  1. using System;
  2. namespace Common.Helper
  3. {
  4. public static class EnumHelper
  5. {
  6. public static int EnumIndex<T>(int value)
  7. {
  8. int i = 0;
  9. foreach (var v in Enum.GetValues(typeof (T)))
  10. {
  11. if ((int) v != value)
  12. {
  13. ++i;
  14. continue;
  15. }
  16. return i;
  17. }
  18. return -1;
  19. }
  20. }
  21. }