我遇到的问题是创建扩展方法!
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
}
我希望上面代码中的注释真的能说明问题——我假设我在做一个巨大的假设并且把它弄错了。
然而,我宁愿通过允许任何枚举调用此功能来使其更有用。最终目标是这样的
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;
}
天涯尽头无女友
鸿蒙传说
相关分类