Created
May 9, 2011 18:43
-
-
Save slpsys/963093 to your computer and use it in GitHub Desktop.
Filtering enum values by a set of strings we want to display, with full type information.
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
// Some enum, could be RateFamilyTypes | |
enum Letters { A, B, C} | |
void Main() | |
{ | |
// List of stringified subset of enum values; could be sourced from XAML | |
HashSet<string> filterList = new HashSet<string>() { "B" }; | |
// Get as typesafe array of enum values (allLetters is an array of Letters) | |
var letterArray = Enum.GetValues(typeof(Letters)); | |
Letters[] allLetters = new Letters[letterArray.Length]; | |
letterArray.CopyTo(allLetters, 0); | |
// Get an IEnumerable or Array of typed enum values, based on the filter list | |
var filteredList = allLetters.Where(x => filterList.Contains(x.ToString())).ToArray(); | |
// Display in dropdown with full type information (filteredList is also an array of Letters) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment