Evaluating enum declaration based on resolved ITypeDefinition

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 2 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 22.1.1
Platform: .NET 4.8
Environment: Windows 10 (64-bit)
Avatar

Hi,

we are switching our C# editor from the old WinForms version (14.1.320) to the latest WPF version. And we are using the parse data to extract informations about the code files. To get all the necessary informations we need to resolve the type references of parameters and return types in methods.

So in this scenario there is no active editor view. We just go through all type definitions in the source files of IProjectAssembly. When we come to a parameter of type IParameterDefinition, we use the resolver to get the type definition (ITypeDefinition) of the corresponding type reference (ITypeReference).

I finally was able to resolve most of the type definitions correctly, but the members of an enum declaration are not in their original order. Instead they are sorted alphabetically, which makes it impossible to get the corresponding integer value. For local enums I can parse the syntax tree, because I have the SourceFileLocation, but for external declarations I am relyant on the infos I receive from the resolver.

Is there any other way to get the values of an external enum declaration, base on the ITypeDefinition instance? Or at least get the members in the correct order?


Best regards, Tobias Lingemann.

Comments (2)

Posted 2 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Another issue seems to be that the base type is always "System.Enum". Even if an integer type like "short" or "ulong" is used. I think this was different in the old release.


Best regards, Tobias Lingemann.

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

Unfortunately we don't track the original order and in the case of .NET reflected data, I'm not sure if those values are guaranteed to come back in a certain order.  Also if you ever assigned specific numeric values to the enum values, the order wouldn't make a difference.

If you need to know the actual numeric value assigned to enum values, it might be best to use Roslyn or reflection to determine them, as that would be reliable regardless of how the values were assigned (implicitly or programmatically).

Regarding the base type, if you use .NET reflection, you also see the BaseType of an enum is "System.Enum".


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.