Created
February 10, 2012 20:10
-
-
Save jirkapenzes/1792382 to your computer and use it in GitHub Desktop.
Get all enum values (for WP7).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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