The problem I'm having is creating the extension method!
public enum TestEnum
{
One, Two, Three, Four
}
public static class EnumExtension
{
public static bool TestMethod(this TestEnum e)
{
return false;
}
}
[TestMethod]
public void TestAll()
{
var result = TestEnum. ; //this only gives the values of the enum (One, Two, Three, Four), there is no option to call the extension method
}
I hope the comment in the code above really shows the issue - I'm assuming I'm making a massive assumption and getting it very wrong.
I however would rather make this more usable, by allowing any enum to call this functionality. The end goal would be something like
public static IEnumerable<string> ConvertToList(this Enum e)
{
var result = new List<string>();
foreach (string name in Enum.GetNames(typeof(e))) //doesn't like e
{
result.Add(name.ToString());
}
return result;
}