diff --git a/src/coreclr/tools/ILTrim/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs b/src/coreclr/tools/ILTrim/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs index c6d6fb893c7..1c8731943e9 100644 --- a/src/coreclr/tools/ILTrim/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs +++ b/src/coreclr/tools/ILTrim/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs @@ -27,6 +27,11 @@ public override IEnumerable GetStaticDependencies(NodeFacto { yield return new(factory.GetNodeForToken(_module, typeDef.BaseType), "Base type of a type"); } + + if (typeDef.IsNested) + { + yield return new DependencyListEntry(factory.TypeDefinition(_module, typeDef.GetDeclaringType()), "Declaring type of a type"); + } } protected override EntityHandle WriteInternal(ModuleWritingContext writeContext) @@ -35,6 +40,10 @@ protected override EntityHandle WriteInternal(ModuleWritingContext writeContext) TypeDefinition typeDef = reader.GetTypeDefinition(Handle); var builder = writeContext.MetadataBuilder; + + if (typeDef.IsNested) + builder.AddNestedType((TypeDefinitionHandle)writeContext.TokenMap.MapToken(Handle), (TypeDefinitionHandle)writeContext.TokenMap.MapToken(typeDef.GetDeclaringType())); + return builder.AddTypeDefinition(typeDef.Attributes, builder.GetOrAddString(reader.GetString(typeDef.Namespace)), builder.GetOrAddString(reader.GetString(typeDef.Name)),