Based on this post, I created a function for myself to do this for me; This is great in Unit Tests, when you want to iterate over all Enum values ββto verify that something works only with certain values.
public static IEnumerable<T> GetEnumValues<T>() { return Enum.GetValues(typeof(T)).Cast<T>(); }
Then I can use it like this:
var values = GetEnumValues<SomeTypeCode>(); var typesToAlwaysShow = values.Where(ScreenAdapter.AlwaysShowThisType).Select(q => (int)q).ToList(); Assert.Equal("101,102,105,205", string.Join(",", typesToAlwaysShow));
source share