Resolving virtual MethodDefinition to base method

30 views
Skip to first unread message

Richard Bennett

unread,
Feb 26, 2019, 12:20:24 PM2/26/19
to mono-cecil
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'd like to be able to get a MethodReference to the base type that will appear in the IL (i.e. System.Object.ToString).

Is there a good way to do this with Mono Cecil other than iterating up through the MethodDefinition's DeclaringType's BaseTypes, resolving each and looking at its method signatures to check for a match?

Reply all
Reply to author
Forward
0 new messages