in src/Refasmer/Importer/ImportLogic.cs [151:220]
private void ImportTypeDefinitionAccessories( TypeDefinitionHandle srcHandle, TypeDefinitionHandle dstHandle)
{
var src = _reader.GetTypeDefinition(srcHandle);
using var _ = WithLogPrefix($"[{_reader.ToString(src)}]");
foreach (var srcInterfaceImplHandle in src.GetInterfaceImplementations())
{
var srcInterfaceImpl = _reader.GetInterfaceImplementation(srcInterfaceImplHandle);
var dstInterfaceHandle = Import(srcInterfaceImpl.Interface);
if (dstInterfaceHandle.IsNil)
{
Trace?.Invoke(
$"Not imported interface implementation {_reader.ToString(srcInterfaceImpl)}");
}
else
{
var dstInterfaceImplHandle = _builder.AddInterfaceImplementation(dstHandle, dstInterfaceHandle);
_interfaceImplementationCache.Add(srcInterfaceImplHandle, dstInterfaceImplHandle);
Trace?.Invoke(
$"Imported interface implementation {_reader.ToString(srcInterfaceImpl)} -> {RowId(dstInterfaceHandle)} {RowId(dstInterfaceImplHandle)}");
}
}
foreach (var srcMethodImplementationHandle in src.GetMethodImplementations())
ImportEntity(srcMethodImplementationHandle, _methodImplementationCache, _reader.GetMethodImplementation,
srcImpl =>
{
var body = Import(srcImpl.MethodBody);
// If the method body wasn't imported (e.g., private explicit interface implementation),
// skip importing the declaration. For generic interfaces, the declaration is a
// MemberReference whose import triggers signature processing. If the signature contains
// internal types that weren't preserved, this would throw UnknownTypeInSignature.
// See: https://github.com/JetBrains/Refasmer/issues/54
//
// Note: a non-generic interface method implementation is not a MemberReference, but a
// MethodDefinition which doesn't trigger signature processing (should be already in the method
// definition cache).
if (body.IsNil)
return default;
var decl = Import(srcImpl.MethodDeclaration);
return decl.IsNil
? default
: _builder.AddMethodImplementation(dstHandle, body, decl);
},
_reader.ToString, IsNil);
if (src.GetEvents().Any())
{
_builder.AddEventMap(dstHandle, NextEventHandle());
foreach (var eventHandle in src.GetEvents())
ImportEvent(eventHandle);
}
if (src.GetProperties().Any())
{
_builder.AddPropertyMap(dstHandle, NextPropertyHandle());
foreach (var propertyHandle in src.GetProperties())
ImportProperty(propertyHandle);
}
if (!src.GetLayout().IsDefault)
{
_builder.AddTypeLayout(dstHandle, (ushort) src.GetLayout().PackingSize, (uint) src.GetLayout().Size);
Trace?.Invoke($"Imported layout Size={src.GetLayout().Size} PackingSize={src.GetLayout().PackingSize}");
}
}