C#或VB.NET - 迭代所有公共枚举 [英] C# or VB.NET - Iterate all Public Enums
本文介绍了C#或VB.NET - 迭代所有公共枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们在源代码中有一个共同的组件,它包含了非常大的应用程序的所有枚举(约300!)。
We have a common component in our source which contains all the enums (approx 300!) for a very large application.
有没有办法使用C#或VB.NET,以迭代所有这些,以便对每一个执行一个操作?
Is there any way, using either C# or VB.NET, to iterate through all of them in order to perform an action on each one?
问题如何迭代.net类中的所有public string属性几乎相关,我正在处理的枚举是各种类型的组合
The question How to iterate all "public string" properties in a .net class is almost relevant but the enums I am dealing with are a mix of types
推荐答案
这些线条有什么区别?
var query = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => t.IsEnum && t.IsPublic);
foreach (Type t in query)
{
Console.WriteLine(t);
}
这篇关于C#或VB.NET - 迭代所有公共枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文