Virtual static interface methods analyzis API #77260
-
I'm trying to analyze following code:
How can I identify which implementation of virtual static method will be invoked from Looks like there was no API added to do that when feature was implemented. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
From inside Main you can use the semantic model to ask about Now that you have this information, you can analyze |
Beta Was this translation helpful? Give feedback.
-
The existing Semantic, IOperation and Symbol models should be sufficient to figure this out :) |
Beta Was this translation helpful? Give feedback.
-
I also recommend our discord channel (https://discord.com/invite/tGJvv88, #roslyn) for questions like this. |
Beta Was this translation helpful? Give feedback.
From inside Main you can use the semantic model to ask about
DoWrapper<StaticVirtualImplementation>();
It will tell you that you are invoking theDoWrapper<T>
method whereT
isStaticVirtualImplementation
. See .ConstructedFrom on theDoWrapper<StaticVirtualImplementation>
method symbol you get to get bacck to theDoWrapper<T>
method.Now that you have this information, you can analyze
DoWrapper<>
. Inside of that you will see that.Do
is a call toIStaticVirtual.Do
throughT
. Knowing thatT
is the ITypeSymbolStaticVirtualImplementation
you can use FindImplementationForInterfaceMember on it with t…