I figured out that I can use GetMembers()
to return the members of the class, but I would like to return only the enum members. While debugging I can hover over member
and see an IsEnum
property that is true
, but I can't seem to get to it in code.
I would like for only IAmAnEnum
to be printed in the following code. Currently the code will print both IAmAnEnum
as well as IAmAClass
.
static void Main(string[] args)
{
foreach (var member in typeof(Test).GetMembers())
{
//if (member.IsEnum) // <-- Compile error
//{
Console.WriteLine(member.Name);
//}
}
Console.Read();
}
public class Test
{
public enum IAmAnEnum
{
}
public class IAmAClass
{
}
}
Aucun commentaire:
Enregistrer un commentaire