Listing all types contained in referenced assemblies

35 views
Skip to first unread message

Sebastian P.

unread,
Sep 26, 2016, 11:09:35 AM9/26/16
to resharper-plugins
Hey,

I'm trying to find all IType/ITypeElements that are contained in a given IAssembly (non-source module)... I'm basically interested in the same information I would see in the R# Assembly Explorer, but programmatically. :)

Starting from an ISolution, I can get ISolution.GetAllAssemblies, but then I'm stuck, because it seems that IAssembly only contains the assemblies meta data, but no details about its content. I could start by collecting all types that are referenced somewhere in any of the solutions source files and try to build-up my own index of IAssembly -> List<ITypeElement>, but a) I would miss references to unused types and b) this seems unnecessary complex for such a seemingly easy look-up task...

I discovered that I can ask the primary PSI module to get all references (<primaryPsiModule>.GetReferences), but this also does not get me any further...

Is there any cache or resolution service I could use to access this kind of information? Any hint is highly appreciated, thanks!

best
Sebastian

Sebastian P.

unread,
Sep 28, 2016, 7:34:11 AM9/28/16
to resharper-plugins
Another option I see is opening the .dll for reflection (Assembly.ReflectionOnlyLoad(...)) and list all Types by calling Assembly.GetTypes. This works as all .dll file paths are contained in the aforementioned meta data, but it still leaves me with the question, how to resolve the C# type in the R# language model to get an ITypeElement.

Matt Ellis

unread,
Sep 29, 2016, 10:21:25 AM9/29/16
to resharper-plugins
Hi Sebastien. I believe my colleague has already replied via email, but for the benefit of the group, this information can be retrieved via IPsiServices.Symbols.GetSymbolScope(). This will give you a "scope" that contains all the information you're after. You can specify the scope by passing in the IPsiModule of the assembly, via IPsiModules.GetPrimaryPsiModule().

The ISymbolScope API is pretty much focused on finding by name, but you can iterate all types by getting the ISymbolScope.GlobalNamespace.GetNestedNamespaces(scope) and for each namespace, call GetNestedTypeElements (note that this doesn't get type elements in all nested namespaces recursively, just gets them in the currently nested namespace).

Hope this helps
Matt

Sebastian P.

unread,
Sep 29, 2016, 10:26:29 AM9/29/16
to resharper-plugins
Hey Matt,

thanks for the reply. I planned to reply to this thread myself as soon as I get it working. Now you were faster. :)

best
Sebastian

Matt Ellis

unread,
Sep 29, 2016, 10:31:43 AM9/29/16
to resharper-plugins
Just out of interest, and because we don't have an API to get you the information you need directly, can I ask why you're after a list of all types? We tend to be navigating directly to something, so we already know the name, and the API is definitely designed for that...

Sebastian P.

unread,
Sep 29, 2016, 1:04:08 PM9/29/16
to resharper-plugins
This is a good question. I can assure you that my use case is so special that no-one else will try to do this... :)

I am a PhD student doing research on recommendation systems for software engineering. More specifically, I'm building a platform that eases the research on such systems, by -for example- providing preprocessed datasets and labelled data that can be used as the ground truth for evaluations of the machine learning part (see [1] for details).

In the course of my studies, I created two datasets: A dataset of interactions of developers within VS that I collected with our KaVE plugin [2] and a second dataset that contains preprocessed versions of many C# solutions from GitHub: the preprocessing captures a simplified representation of the AST for all contained types in the solutions. As an extension, I would also like to preserve some information about the type system in a simplified form. This is where this thread comes into place...

Technically speaking, we are "abusing" the BaseTestWithExistingSolution to open the solutions in the cloned repos. We are iterating over all contained types and transform the AST (and soon the typing info :)). Even though it feels that this base test was never designed for such a task (don't ask me for a list of bugs :)), it is the only way we found to bulk process that many solutions, after the plugin support from the R# command line tools was dropped (with the transition from R#8.2 to R#9.0, I think).

Does this answer you question? :D

best
Sebastian

Matt Ellis

unread,
Sep 30, 2016, 4:41:18 AM9/30/16
to resharper-plugins
Yep! Very interesting scenario :)

Thanks!
Matt
Reply all
Reply to author
Forward
0 new messages