Re: [mono-cecil] Determining the base method for a virtual method

62 views
Skip to first unread message

Greg Young

unread,
Feb 26, 2019, 1:21:03 PM2/26/19
to mono-...@googlegroups.com
So you appear to have a few questions like this ... The code from the minimizer in MightyMoose already does alot of these types of things (and many are implemented as extension methods its from an old cecil so there might be newer methods added that make these redundant)

https://github.com/continuoustests/ContinuousTests/blob/master/src/AutoTest.Minimizer/Extensions/MethodDefinitionExtensions.cs (there are others if you look through). If nothing else its probably a good starting point for you.

Cheers,

Greg 

On Tue, Feb 26, 2019 at 12:20 PM 'Richard Bennett' via mono-cecil <mono-...@googlegroups.com> wrote:
void Main()
{
  Console.WriteLine(new Foo().ToString());
}

class Foo
{
  public override string ToString()
  {
    return "Foo";
  }
}

In the above, the Foo.ToString call appears in IL as

callvirt    System.Object.ToString

Given the MethodDefinition of Foo.ToString, I want to get a MethodReference to the base method that will appear in IL (i.e. System.Object.ToString in this case).

Is there a good way to do this with Mono Cecil other than getting the DeclaringType and iterating up through BaseTypes, resolving them and checking their methods for signature matches?

--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Studying for the Turing test

Richard Bennett

unread,
Feb 26, 2019, 1:40:04 PM2/26/19
to mono-cecil
Ah yes, I posted twice as I was trying to do it on mobile from a train...

GetInheritanceHierarchy looks promising, thanks for that. Will give it a go tomorrow

Reply all
Reply to author
Forward
0 new messages