Lokad / ILPack

Serialize .NET Core assemblies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing method override

vermorel opened this issue · comments

Based on #84, it seems that we are not emitting the IL that encodes the overriding behavior of a method.

@vermorel I observed interface implementation are handled with current codebase and ILDASM shows .override keyword in generated assemblies. Relevant parts:

// Explicit interface implementations need to be marked with method implementation
// (This is the equivalent of .Override in msil)
if (method.IsPrivate)
{
// Go through all the implemented interfaces and all their methods
// looking for methods that this method implements and mark accordingly.
// NB: This is not super efficient. Should probably create a map somewhere
// for faster lookup, but this will do for now.
var type = method.DeclaringType;
foreach (var itf in type.GetInterfaces())
{
var itfMap = type.GetInterfaceMap(itf);
for (int i = 0; i < itfMap.TargetMethods.Length; i++)
{
var m = itfMap.TargetMethods[i];
if (m == method)
{
var itfImpl = itfMap.InterfaceMethods[i];
_metadata.Builder.AddMethodImplementation((TypeDefinitionHandle)_metadata.GetTypeHandle(method.DeclaringType), handle, _metadata.GetMethodHandle(itfImpl));
}
}
}
}

Could you clarify if it's something different, please?

I put this in to get explicit interface method implementations working. I did a couple of quick tests with the C# compiler and abstract/virtual methods and didn't see the .override directive. I didn't test method overrides though as figured I'd get back to it at a later date.

@toptensoftware Yes, I confirm that .override is only generated for interface implementations. Abstract/virtual methods do not cause to generate .override.

Test cases for this in PR #90. I also checked the ildasm, and couldn't see C# compiler generating .overrides for any of these.

Excellent!