enumerate all types in a solution

hi!

i cannot find a simple way to do this simple thing:

i'm in the Populate method of a GeneratorProviderBase derived type and I need to browse all the types in the solution.
i also need to retrieve members of these types

i looked at the examples, but type searches are always done in the "current context", i.e. for example where "alt + ins" were pressed for a generator.
i need a context free search.

thanks

2 comments
Comment actions Permalink

Generally speaking, there isn't a terribly easy way to get all of the types in a solution, because this is likely to be a huge data set, and costly to enumerate. Typically, you'd be working with e.g. the members of an existing type, all of the types in a file or referenced assembly, or inheriting types. ReSharper has APIs for getting at this information. Is there something specific you want to do with the full list of types? There might be an easier way to do the thing you're after.

0
Comment actions Permalink

the goal is to provide a list of type in which the dev can choose.
when he chose the type, then he can "sync" properties between this type and the type in which he pressed alt+ins.
one use of this (but not limited to) is to keep in sync data classes and viewmodel classes, especially to copy some attributes from the data class (localization, validation,...)

i managed to browse the type in the solution using this:

ISolution solution = .......................

var symbolCache = solution.GetComponent<ISymbolCache>();

            var classList = symbolCache
                .Parts
                .EnumerateContents()
                .Select(o => o.Key)
                .SelectMany(symbolCache.GetTypesAndNamespacesInFile)
                .OfType<Class>()
                .ToList();

which fast enough for us.


but i would also like to include referenced types, i.e. classes defined in compiled referenced assemblies.

any clue how to do this?

0

Please sign in to leave a comment.