> My test class looks the following:
>
[...]
>         public void Test3()
>         {
>             Console.WriteLine(test2);
>         }
>
>     }
>
>     class Test : Class1
>     {
>         public void Test3()
>         {
>
>         }
>     }

In this test case, there is no override. There are two methods,
Class1.Test3 and Test.Test3. Neither method is virtual.

> So my code to check is:
>
> foreach (MethodDefinition method in type.Methods)
>             {
>
>                 if (method.IsVirtual && !method.IsNewSlot)
>                 {
>                     Console.WriteLine("Inherited");
>                 }

Since the methods given above are not virtual (and I think they're
also newslot), the if block is not executed.
Also note that this if block checks for overrides (as in C#
"override"), not inherited methods. Iterate the base types'
collections to get inherited members.

> However, Inherited is never printed on the console, and both classes have a
> total amount of methods of 1

As Jb said:

>> The .Methods on the type only contain the methods that are actually
>> declared on the type.

For both types, there is only one method declared on each.

If you're unsure about how Cecil works, the following usually help:

- Inspect your program using .NET's IL Disassembler (ildasm.exe). It
will show you flags and similar.
- Read up on the .NET metadata table format in the .NET CLI
specification (ECMA-335, Partition II). This will explain why a
certain metadata object has certain properties and what the flags
mean.
- Use a debugger to inspect the object model.

Regards,
Fabian

-- 
--
mono-cecil

Reply via email to