private void AddParts( IAnonymousTypeDisplayService anonymousTypeService, ArrayBuilder <SymbolDisplayPart> finalParts, ImmutableArray <SymbolDisplayPart> parts, SemanticModel semanticModel, int position, HashSet <INamedTypeSymbol>?seenSymbols = null) { seenSymbols ??= new(); foreach (var part in parts) { if (part.Symbol is INamedTypeSymbol { IsAnonymousType: true } anonymousType) { if (seenSymbols.Add(anonymousType)) { var anonymousParts = anonymousTypeService.GetAnonymousTypeParts(anonymousType, semanticModel, position); AddParts(anonymousTypeService, finalParts, anonymousParts, semanticModel, position, seenSymbols); seenSymbols.Remove(anonymousType); } else { finalParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, symbol: null, "...")); } }
public static IList <SymbolDisplayPart> InlineDelegateAnonymousTypes( this IAnonymousTypeDisplayService service, IList <SymbolDisplayPart> parts, SemanticModel semanticModel, int position ) { var result = parts; while (true) { var delegateAnonymousType = result .Select(p => p.Symbol) .OfType <INamedTypeSymbol>() .FirstOrDefault(s => s.IsAnonymousDelegateType()); if (delegateAnonymousType == null) { break; } result = result == parts ? new List <SymbolDisplayPart>(parts) : result; ReplaceAnonymousType( result, delegateAnonymousType, service.GetAnonymousTypeParts(delegateAnonymousType, semanticModel, position) ); } return(result); }