public static ImmutableArray <SymbolDisplayPart> RemoveAttributeSuffix(ImmutableArray <SymbolDisplayPart> parts) { SymbolDisplayPart part = parts.FirstOrDefault(f => f.Kind == SymbolDisplayPartKind.ClassName); Debug.Assert(part.Kind == SymbolDisplayPartKind.ClassName, part.Kind.ToString()); if (part.Kind == SymbolDisplayPartKind.ClassName) { const string attributeSuffix = "Attribute"; string text = part.ToString(); if (text.EndsWith(attributeSuffix, StringComparison.Ordinal)) { parts = parts.Replace(part, part.WithText(text.Remove(text.Length - attributeSuffix.Length))); } } return(parts); }
private static void AddDisplayParts( this ImmutableArray <SymbolDisplayPart> .Builder parts, ISymbol symbol, SymbolDisplayFormat format, SymbolDisplayAdditionalOptions additionalOptions, bool removeAttributeSuffix = false) { SymbolDisplayFormat format2; if (additionalOptions.HasOption(SymbolDisplayAdditionalOptions.OmitContainingNamespace)) { format2 = TypeSymbolDisplayFormats.Name_ContainingTypes_SpecialTypes; } else if (format.GlobalNamespaceStyle == SymbolDisplayGlobalNamespaceStyle.Included) { format2 = TypeSymbolDisplayFormats.Name_ContainingTypes_Namespaces_GlobalNamespace_SpecialTypes; } else { format2 = TypeSymbolDisplayFormats.Name_ContainingTypes_Namespaces_SpecialTypes; } parts.AddRange(symbol.ToDisplayParts(format2)); if (!(symbol is INamedTypeSymbol typeSymbol)) { return; } if (removeAttributeSuffix) { SymbolDisplayPart last = parts.Last(); if (last.Kind == SymbolDisplayPartKind.ClassName) { const string attributeSuffix = "Attribute"; string text = last.ToString(); if (text.EndsWith(attributeSuffix, StringComparison.Ordinal)) { parts[parts.Count - 1] = last.WithText(text.Remove(text.Length - attributeSuffix.Length)); } } } ImmutableArray <ITypeSymbol> typeArguments = typeSymbol.TypeArguments; ImmutableArray <ITypeSymbol> .Enumerator en = typeArguments.GetEnumerator(); if (en.MoveNext()) { parts.AddPunctuation("<"); while (true) { if (en.Current.Kind == SymbolKind.NamedType) { parts.AddDisplayParts((INamedTypeSymbol)en.Current, format, additionalOptions); } else { Debug.Assert(en.Current.Kind == SymbolKind.TypeParameter, en.Current.Kind.ToString()); parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.TypeParameterName, en.Current, en.Current.Name)); } if (en.MoveNext()) { parts.AddPunctuation(","); parts.AddSpace(); } else { break; } } parts.AddPunctuation(">"); } }