We're updating the issue view to help you get more done. 

Support method overriding and shadowing

Description

The TypePipe should support adding methods with the same name and signature as methods declared by base types, either as a redeclaration (like "new" methods in C#) or as a method override.

To create a method shadowing a base method:

  • Use MutableType.AddMethod to declare a method with the desired name and signature, giving it the flag MethodAttributes.NewSlot if the method is to be virtual as well, or just don't make it virtual.

  • Note that you cannot add a method with the same name and signature as another method declared on the MutableType (or the original type) itself.

To create a method overriding a base method:

  • Use MutableType.AddMethod to declare a method with the desired name and signature, giving it the flags MethodAttributes.ReuseSlot and MethodAttributes.Virtual. The new method will automatically override the existing one.

  • Alternatively, use MutableType.AddMethod to declare a method with a different name and the desired signature, then use MutableMethodInfo.AddExplicitBaseDefinition to declare the method as an override for a different method.

  • Alternatively, use MutableType.GetOrAddMutableMethod to get a MutableMethodInfo for a base method, then use SetBody to change the implementation. GetOrAddMutableMethod will automatically create an override for the given method (or return an existing override). If the overridden method is shadowed by another method, the override will have a different name than the overridden method. This ensures that multiple (independent) virtual methods with the same name in an inheritance hierarchy can be overridden.

    • When using GetOrAddMutableMethod, you don't need to differentiate between overriding base methods and changing methods on the mutated type. If you need more control over the name of the method override, use AddMethod instead.

  • Note that you cannot create an override with the same name and signature as another method declared on the MutableType (or the original type) itself. Use GetOrAddMutableMethod and SetBody instead.

Assignee

User known

Reporter

Fabian Schmied

Labels

None

Time tracking

0m

Components

Fix versions

Priority

Normal
Configure