@@ -122,6 +122,24 @@ public static bool ContainsTypeParameters(this ITypeSymbol type, Context cx, ISy
122122 }
123123 }
124124
125+ /// <summary>
126+ /// Write the identifier for the symbol <paramref name="type"/> to the trapfile <paramref name="trapFile"/>.
127+ /// If any nested types are found in the identifier, then they are written out explicitly, without
128+ /// prefixing the assembly ID.
129+ /// </summary>
130+ /// <param name="type">The type to write.</param>
131+ /// <param name="cx">The extraction context.</param>
132+ /// <param name="trapFile">The trap file to write to.</param>
133+ /// <param name="symbolBeingDefined">The outer symbol being defined (to avoid recursive ids).</param>
134+ public static void BuildNestedTypeId ( this ITypeSymbol type , Context cx , TextWriter trapFile , ISymbol symbolBeingDefined )
135+ {
136+ void WriteType ( Context cx , TextWriter trapFile , ITypeSymbol symbol , ISymbol symbolBeingDefined )
137+ {
138+ symbol . BuildTypeId ( cx , trapFile , false , symbolBeingDefined , WriteType ) ;
139+ }
140+ WriteType ( cx , trapFile , type , symbolBeingDefined ) ;
141+ }
142+
125143 /// <summary>
126144 /// Constructs a unique string for this type symbol.
127145 ///
@@ -130,8 +148,10 @@ public static bool ContainsTypeParameters(this ITypeSymbol type, Context cx, ISy
130148 /// </summary>
131149 /// <param name="cx">The extraction context.</param>
132150 /// <param name="trapFile">The trap builder used to store the result.</param>
151+ /// <param name="prefix">Whether to prefix the type ID with the assembly ID.</param>
152+ /// <param name="symbolBeingDefined">The outer symbol being defined (to avoid recursive ids).</param>
133153 /// <param name="subTermAction">The action to apply to syntactic sub terms of this type.</param>
134- public static void BuildTypeId ( this ITypeSymbol type , Context cx , TextWriter trapFile , bool prefix , ISymbol SymbolBeingDefined , Action < Context , TextWriter , ITypeSymbol , ISymbol > subTermAction )
154+ public static void BuildTypeId ( this ITypeSymbol type , Context cx , TextWriter trapFile , bool prefix , ISymbol symbolBeingDefined , Action < Context , TextWriter , ITypeSymbol , ISymbol > subTermAction )
135155 {
136156 if ( type . SpecialType != SpecialType . None && ! ( type is INamedTypeSymbol n && n . IsGenericType ) )
137157 {
@@ -150,7 +170,7 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
150170 {
151171 case TypeKind . Array :
152172 var array = ( IArrayTypeSymbol ) type ;
153- subTermAction ( cx , trapFile , array . ElementType , SymbolBeingDefined ) ;
173+ subTermAction ( cx , trapFile , array . ElementType , symbolBeingDefined ) ;
154174 array . BuildArraySuffix ( trapFile ) ;
155175 return ;
156176 case TypeKind . Class :
@@ -160,16 +180,16 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
160180 case TypeKind . Delegate :
161181 case TypeKind . Error :
162182 var named = ( INamedTypeSymbol ) type ;
163- named . BuildNamedTypeId ( cx , trapFile , prefix , SymbolBeingDefined , subTermAction ) ;
183+ named . BuildNamedTypeId ( cx , trapFile , prefix , symbolBeingDefined , subTermAction ) ;
164184 return ;
165185 case TypeKind . Pointer :
166186 var ptr = ( IPointerTypeSymbol ) type ;
167- subTermAction ( cx , trapFile , ptr . PointedAtType , SymbolBeingDefined ) ;
187+ subTermAction ( cx , trapFile , ptr . PointedAtType , symbolBeingDefined ) ;
168188 trapFile . Write ( '*' ) ;
169189 return ;
170190 case TypeKind . TypeParameter :
171191 var tp = ( ITypeParameterSymbol ) type ;
172- if ( ! SymbolEqualityComparer . Default . Equals ( tp . ContainingSymbol , SymbolBeingDefined ) )
192+ if ( ! SymbolEqualityComparer . Default . Equals ( tp . ContainingSymbol , symbolBeingDefined ) )
173193 {
174194 switch ( tp . TypeParameterKind )
175195 {
@@ -179,7 +199,7 @@ public static void BuildTypeId(this ITypeSymbol type, Context cx, TextWriter tra
179199 trapFile . Write ( '_' ) ;
180200 break ;
181201 case TypeParameterKind . Type :
182- subTermAction ( cx , trapFile , tp . ContainingType , SymbolBeingDefined ) ;
202+ subTermAction ( cx , trapFile , tp . ContainingType , symbolBeingDefined ) ;
183203 trapFile . Write ( '_' ) ;
184204 break ;
185205 }
0 commit comments