bee3
bee3

Reputation: 25

Get method's implementation with Roslyn

If for example, I declare an interface class whose actual class type will only be determined on runtime, and by using VisualStudio when I right click the method call and click "Go To Implementation" I can find 3 implementations from classes that inherits the interface.

How can I, using Roslyn, get the method's implementation syntax nodes/symbols?

Upvotes: 1

Views: 1369

Answers (2)

SLaks
SLaks

Reputation: 887195

You're looking for SymbolFinder.FindImplementationsAsync.

Upvotes: 1

Jason Malinowski
Jason Malinowski

Reputation: 18976

Just look at the code that implements Go To Implementation. There's several public APIs on the SymbolFinder type that give you overrides/implementations/derived types, and each give you symbols back. Most of the code in the feature is just figuring out which is the right method to call, with some extra filtering that's specific for the feature. For example, if you have a derived type that's got an abstract member, the core functions will return that method, but it's not an implementation in a meaningful way for the sake of the feature.

Upvotes: 1

Related Questions