EnumHelper.cs 307 B

123456789101112131415161718192021
  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 (object v in Enum.GetValues(typeof (T)))
  10. {
  11. if ((int) v == value)
  12. {
  13. return i;
  14. }
  15. ++i;
  16. }
  17. return -1;
  18. }
  19. }
  20. }