How to list the possible values of an enum?

So I am inspecting a ToString() call on an enum variable.  How do I get the enumerator list of that enum?

I've gotten as far as getting an ITypeElement and confirming it is an enum type.  But now I'm not sure how to proceed.

public override void VisitInvocationExpression(IInvocationExpression invocationExpressionParam)
    IReferenceExpression expression = invocationExpressionParam.InvokedExpression as IReferenceExpression;
    if (expression == null)

    var rer = expression.Reference as IReferenceExpressionReference;
    if(rer == null)

    ResolveResult resolveResult = rer.Resolve();

    IDeclaredElement e = resolveResult.DeclaredElement;
    if(e == null)
    ITypeElement containingType = e.GetContainingType();
    if(containingType == null)

    if( containingType.CLRName != "System.Enum" )

    string[] enumlistnames = ??????


Comment actions Permalink

var type = TypeFactory.CreateType(typeElement);
var symbolTable = type.GetSymbolTable;

Once you got symbol table for the type it contains all members declared in
as well as inherited members like ToString(). The only thing left is to
filter out enum members from the table. You can do it using Filter maethod.
Declared element are filtered as declaredElement.GetElementType() ==

Sergey V. Coox
JetBrains, Inc
"Develop with pleasure!"

Comment actions Permalink

Hi Sergey,

Thanks for the help.  I'm not where I want to be yet though. 

I did like you said, and I can see all the members of System.Enum in the symbol table. I can't see the members of my enum type.

For some context, the code I am analyzing looks like below.  I am analyzing the invocation against the variable e within the if statement.  I do not see the members 'First' and 'Second' in the symbol table.

enum MyEnum { First, Second }
void foo(MyEnum e) {
     if(e.ToString() == "First"){

I am thinking that the problem might be when I am resolving perhaps?  Should I not be getting an ITypeElement for 'MyEnum' type instead of a 'System.Enum' type?


Please sign in to leave a comment.