Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
Created January 31, 2019 09:18
Show Gist options
  • Save CapitanLiteral/192ebdfa506af905ebe18e23f5bd3c6f to your computer and use it in GitHub Desktop.
Save CapitanLiteral/192ebdfa506af905ebe18e23f5bd3c6f to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
public class EnumUtils<T>
{
public static IEnumerable<T> GetAllValues()
{
return System.Enum.GetValues(typeof(T)).Cast<T>();
}
public static int GetNumberOfValues()
{
return System.Enum.GetNames(typeof(T)).Length;
}
public static T ParseString(string inString)
{
return (T)System.Enum.Parse(typeof(T), inString, true);
}
public static string ToString(T type)
{
return System.Enum.GetName(typeof(T), type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment