public TypeDefinition Import(TypeDefinition type, Collection <TypeDefinition> col, bool internalize) { _logger.Verbose("- Importing " + type); 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 = "<" + Guid.NewGuid() + ">" + nt.Name; _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) { Import(nested, nt.NestedTypes, false); } foreach (FieldDefinition field in type.Fields) { CloneTo(field, nt); } // methods before fields / events foreach (MethodDefinition meth in type.Methods) { CloneTo(meth, nt, justCreatedType); } foreach (EventDefinition evt in type.Events) { CloneTo(evt, nt, nt.Events); } foreach (PropertyDefinition prop in type.Properties) { CloneTo(prop, nt, nt.Properties); } return(nt); }