Пример #1
0
        private void AddParts(
            IStructuralTypeDisplayService 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 IStructuralTypeDisplayService 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);
        }