No, it's not possible.

See:

--
abstract class Foo
{
    public abstract int Do();
}

class Bar : Foo
{
    public override int Do()
    {
        return 2;
    }
}

class Baz : Foo
{
    public override int Do()
    {
        return 42;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Foo f;

        if (args.Length == 0)
            f = new Bar();
        else
            f = new Baz();

        Console.WriteLine(f.Do());
    }
}
--

Look at the expression:

f.Do();

At the IL level, what Cecil sees, all you'll get it is:

callvirt int Foo::Do()

There's no way, at the Cecil level, to know if Bar.Do() or Baz.Do()
will be called.

Jb


On Fri, Jan 11, 2013 at 9:45 AM, Kasper Stolk <[email protected]> wrote:
> So it's unfortunately not possible to find out?
>
>
> On Wednesday, 9 January 2013 23:47:21 UTC+1, Kasper Stolk wrote:
>>
>> Thank you Jon,
>>
>> The method is virtual indeed.
>> Can I use Cecil to invoke that method to determine that? What I have is
>> the MethodDefinition from the Body.Instructions.
>>
>>
>>
>> Groeten,
>> Kasper
>>
>>
>> On Wed, Jan 9, 2013 at 11:12 PM, Jonathan Pryor <[email protected]> wrote:
>>>
>>> On Jan 9, 2013, at 3:59 PM, Kasper Stolk <[email protected]> wrote:
>>> > How can I get the reference to the overridden class? Is it determined
>>> > at runtime?
>>>
>>> If the method is virtual, then the method to invoke is determined at
>>> runtime.
>>>
>>>  - Jon
>>>
>>> --
>>> --
>>> mono-cecil
>>
>>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to