EnumHelper.cs 421 B

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