I am using EnvDTE to generate some code in my latest project.
I have a reference to a CodeClass-Object for a given C#-Class but now I wanted to loop through all of its members (in codeClass.Members) and check their types.
However I can’t manage to retrieve the type of the given member from the CodeElement-Object that I get when looping through codeClass.Members.
How can I retrieve the type (int, string etc.)?
PS: Reflection is not an option for my usecase.
CodeElement has the Members property, which is a collection of CodeElement. CodeElement has a Kind property, from which you can know what kind of member we’re talking about. Then you can cast each member to the appropriate interface and have a look around. Most subclasses have a Type property, with the info you are looking for.
I typed this in the Macro editor, in a module:
It simply takes the class that is where the cursor is in the editor and displays the type info for any field or property.