简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM