oleksii
5/29/2017 - 10:25 PM

EnumExtensions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

public static class Enum<TEnum> where TEnum: struct
{
    static Enum()
    {
        if (!typeof(TEnum).GetTypeInfo().IsEnum)
            throw new ArgumentException($"{typeof(TEnum).FullName} is not an enum.", nameof(TEnum));
    }

    public static IEnumerable<TEnum> GetValues() => Enum.GetValues(typeof(TEnum)).Cast<TEnum>();

    public static TEnum Parse(string value) => (TEnum)Enum.Parse(typeof(TEnum), value);
}