我遇到的問題是創建擴展方法!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;}
- 2 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
0/150
提交
取消