I want to do something like this:
enum MyEnum { None, One, Two };
var myEnumValues = MyEnum.Values();
My extension method:
public static IEnumerable<T> Values<T>(this Enum enumeration)
where T : struct
=> Enum.GetValues(typeof(T)).Cast<T>();
But it looks this way:
MyEnum.None.Values<MyEnum>();
How to do it?
Extension methods are static methods that are applied to an instance of an object.
MyEnum is a type, and not an instance, so you can't add extension methods to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With