Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public static class Enum<T> where T : struct, IComparable, IFormattable, IConvertible
  5. {
  6. private static T[] _values;
  7.  
  8. static Enum() {
  9. if(!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type!");
  10. }
  11.  
  12. public static T[] GetValues() => _values ?? (_values = Enum.GetValues(typeof(T)).Cast<T>().ToArray());
  13.  
  14. public static T Parse(string value) => (T)Enum.Parse(typeof(T), value);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement