Skip to content

Instantly share code, notes, and snippets.

@jirkapenzes
Created February 10, 2012 20:10
Show Gist options
  • Save jirkapenzes/1792382 to your computer and use it in GitHub Desktop.
Save jirkapenzes/1792382 to your computer and use it in GitHub Desktop.
Get all enum values (for WP7).
using System.Linq;
using System.Collections.Generic;
namespace EnumHelper {
public class EnumHelper {
/// <summary>
/// Get all enum values.
/// </summary>
/// <typeparam name="TEnum">Enum type.</typeparam>
/// <returns>Collection of all enum types.</returns>
public static IEnumerable<TEnum> GetEnumValues<TEnum>() where TEnum : new() {
return typeof(TEnum).GetFields()
.Select(fieldInfo => (TEnum)fieldInfo.GetValue(new TEnum()))
.Distinct().AsEnumerable();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment