private static Dictionary TypeImportPass()

in src/Refasmer/Importer/ImportLogic.cs [580:638]


    private static Dictionary<TypeDefinitionHandle, TypeDefinitionHandle> TypeImportPass(
        MetadataReader reader,
        HashSet<TypeDefinitionHandle> internalTypesToPreserve,
        IImportFilter? filter,
        Action<string>? traceLog)
    {
        var checker = new CachedAttributeChecker();
        var typeDefinitions = new Dictionary<TypeDefinitionHandle, TypeDefinitionHandle>();
        var index = 1;
        foreach (var srcHandle in reader.TypeDefinitions)
        {
            bool shouldImport;

            var src = reader.GetTypeDefinition(srcHandle);

            // Special <Module> type
            if (srcHandle.GetHashCode() == 1 && reader.GetString(src.Name) == "<Module>")
            {
                shouldImport = true;
            }
            else if (checker.HasAttribute(reader, src, FullNames.Embedded) &&
                     checker.HasAttribute(reader, src, FullNames.CompilerGenerated))
            {
                traceLog?.Invoke($"Embedded type found {reader.ToString(srcHandle)}");
                shouldImport = true;
            }
            else if (reader.GetString(src.Namespace) == FullNames.CompilerServices &&
                     reader.GetFullname(src.BaseType) == FullNames.Attribute)
            {
                traceLog?.Invoke($"CompilerServices attribute found {reader.ToString(srcHandle)}");
                shouldImport = true;
            }
            else if (reader.GetString(src.Namespace) == FullNames.CodeAnalysis &&
                     reader.GetFullname(src.BaseType) == FullNames.Attribute)
            {
                traceLog?.Invoke($"CodeAnalysis attribute found {reader.ToString(srcHandle)}");
                shouldImport = true;
            }
            else if (internalTypesToPreserve.Contains(srcHandle))
            {
                shouldImport = true;
            }
            else
            {
                shouldImport = filter?.AllowImport(reader.GetTypeDefinition(srcHandle), reader) != false;
            }

            if (shouldImport)
            {
                typeDefinitions[srcHandle] = MetadataTokens.TypeDefinitionHandle(index++);
            }
            else
            {
                traceLog?.Invoke($"Type filtered and will not be imported {reader.ToString(srcHandle)}");
            }
        }

        return typeDefinitions;
    }