Method override resolution in the code


#1

I’m looking for the source code that implements the resolution of overridden methods. If a type defines a virtual method, and a derived type defines a virtual method of the same name and signature and no newslot flag, then the second method may be called depending on the situation. As far as I know, this override relationship is nowhere explicitly encoded in the assembly file, at least not mandatory (and C# compilers don’t generally set the .override directive in IL).

But where in the code can I find that part?

Specifically I’m looking for a function that for any given derived-type method and base type will pick the one method that it overrides. Or the other way around. How is the decision made whether any one of two methods overrides the other? Especially when the base type has generics and the base method has a generic parameter where the overriding method has a concrete non-generic type.


#2

Nevermind, I didn’t find it but I don’t need it anymore. (Can’t delete my thread.)


#3

As an aside, I think you’d find that the code you’d need to look at for this would not be super compact.

Here’s a doc to start with: https://github.com/dotnet/coreclr/blob/master/Documentation/botr/type-system.md.


.NET Foundation Website | Blog | Projects | Code of Conduct