Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public static class Enum<T> where T : struct, IComparable, IFormattable, IConvertible
- {
- private static T[] _values;
- static Enum() {
- if(!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type!");
- }
- public static T[] GetValues() => _values ?? (_values = Enum.GetValues(typeof(T)).Cast<T>().ToArray());
- public static T Parse(string value) => (T)Enum.Parse(typeof(T), value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement