@@ -306,11 +306,8 @@ static PropertyInfo GetAttributeProperty(Type type, string name)
306306 return typeBuilder ;
307307 }
308308
309- // Ensure the base type is built before building the derived type.
310- if ( baseType != null )
311- {
312- BuildBaseType ( typeSymbol ) ;
313- }
309+ // Ensure the base type and interfaces are built before building the derived type.
310+ BuildBaseTypeAndInterfaces ( typeSymbol ) ;
314311
315312 // Ensure this type is only built once.
316313 if ( SymbolicTypes . TryGetValue ( typeFullName , out thisType ) && thisType is not TypeBuilder )
@@ -321,18 +318,28 @@ static PropertyInfo GetAttributeProperty(Type type, string name)
321318 return typeBuilder . CreateType ( ) ! ;
322319 }
323320
324- private static void BuildBaseType ( INamedTypeSymbol typeSymbol )
321+ private static void BuildBaseTypeAndInterfaces ( INamedTypeSymbol typeSymbol )
325322 {
326- string baseTypeFullName = GetTypeSymbolFullName ( typeSymbol . BaseType ! ) ;
327- if ( SymbolicTypes . TryGetValue ( baseTypeFullName , out Type ? baseType ) &&
328- baseType is TypeBuilder baseTypeBuilder )
323+ if ( typeSymbol . BaseType != null )
329324 {
330- if ( typeSymbol . BaseType != null )
325+ BuildBaseTypeAndInterfaces ( typeSymbol . BaseType ) ;
326+
327+ string baseTypeFullName = GetTypeSymbolFullName ( typeSymbol . BaseType ! ) ;
328+ if ( SymbolicTypes . TryGetValue ( baseTypeFullName , out Type ? baseType ) &&
329+ baseType is TypeBuilder baseTypeBuilder )
331330 {
332- BuildBaseType ( typeSymbol . BaseType ) ;
331+ baseTypeBuilder . CreateType ( ) ;
333332 }
333+ }
334334
335- baseTypeBuilder . CreateType ( ) ;
335+ foreach ( INamedTypeSymbol interfaceTypeSymbol in typeSymbol . Interfaces )
336+ {
337+ string interfaceTypeFullName = GetTypeSymbolFullName ( interfaceTypeSymbol ) ;
338+ if ( SymbolicTypes . TryGetValue ( interfaceTypeFullName , out Type ? interfaceType ) &&
339+ interfaceType is TypeBuilder interfaceTypeBuilder )
340+ {
341+ interfaceTypeBuilder . CreateType ( ) ;
342+ }
336343 }
337344 }
338345
@@ -341,7 +348,8 @@ private static void BuildSymbolicTypeMembers(
341348 TypeBuilder typeBuilder ,
342349 Type [ ] ? genericTypeParameters )
343350 {
344- foreach ( Type interfaceType in typeSymbol . Interfaces . Select ( AsType ) )
351+ foreach ( Type interfaceType in typeSymbol . Interfaces . Select (
352+ ( i ) => i . AsType ( genericTypeParameters ) ) )
345353 {
346354 typeBuilder . AddInterfaceImplementation ( interfaceType ) ;
347355 }
0 commit comments