From deb28fed8630d95e32ea66c5ed86cc0a15df56a3 Mon Sep 17 00:00:00 2001 From: Tlakaelel Axayakatl Ceja Date: Thu, 7 Oct 2021 04:41:43 -0700 Subject: [PATCH] Add Support for NestedTypes (#8) --- .../DependencyAnalysis/TokenBased/TypeDefinitionNode.cs | 9 +++++++++ 1 file changed, 9 insertions(+) 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)),