in ILRepack/RepackImporter.cs [130:218]
public TypeDefinition Import(TypeDefinition type, Collection<TypeDefinition> col, bool internalize)
{
_logger.Verbose("- Importing " + type);
if (ShouldDrop(type))
{
return null;
}
TypeDefinition nt = _repackContext.TargetAssemblyMainModule.GetType(type.FullName);
bool justCreatedType = false;
if (nt == null)
{
nt = CreateType(type, col, internalize, null);
justCreatedType = true;
}
else if (DuplicateTypeAllowed(type))
{
_logger.Info("Merging " + type);
}
else if (!type.IsPublic || internalize)
{
// rename the type previously imported.
// renaming the new one before import made Cecil throw an exception.
string other = GenerateName(nt);
_logger.Info("Renaming " + nt.FullName + " into " + other);
nt.Name = other;
nt = CreateType(type, col, internalize, null);
justCreatedType = true;
}
else if (_options.UnionMerge)
{
_logger.Info("Merging " + type);
}
else
{
_logger.Error("Duplicate type " + type);
throw new InvalidOperationException(
"Duplicate type " + type + " from " + type.Scope + ", was also present in " +
MappingHandler.GetScopeFullName(_repackContext.MappingHandler.GetOrigTypeScope<IMetadataScope>(nt)));
}
_repackContext.MappingHandler.StoreRemappedType(type, nt);
// nested types first (are never internalized)
foreach (TypeDefinition nested in type.NestedTypes)
{
if (ShouldDrop(nested) == false)
{
Import(nested, nt.NestedTypes, false);
}
}
foreach (FieldDefinition field in type.Fields)
{
if (ShouldDrop(field) == false)
{
CloneTo(field, nt);
}
}
// methods before fields / events
foreach (MethodDefinition meth in type.Methods)
{
if (ShouldDrop(meth) == false)
{
CloneTo(meth, nt, justCreatedType);
}
}
foreach (EventDefinition evt in type.Events)
{
if (ShouldDrop(evt) == false)
{
CloneTo(evt, nt, nt.Events);
}
}
foreach (PropertyDefinition prop in type.Properties)
{
if (ShouldDrop(prop) == false)
{
CloneTo(prop, nt, nt.Properties);
}
}
if (internalize && _options.RenameInternalized && !IsModuleTag(nt))
{
string newName = GenerateName(nt);
_logger.Verbose("Renaming " + nt.FullName + " into " + newName);
nt.Name = newName;
}
return nt;
}