Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.CodeAnalysis;

public static class INamedTypeSymbolExtensions
Expand All @@ -16,4 +17,26 @@ public static bool IsAccessibleOutsideOfAssembly(this ISymbol symbol) =>
Accessibility.Public => true,
_ => true, //Here should be some reasonable default
};

/// <summary>
/// Converts a type symbol to its normalized display string representation. For generic types, this returns the
/// unbounded generic form (e.g., "IMarker` `" instead of "IMarker`T`"). For non-generic types, returns the
/// standard display string.
/// </summary>
/// <param name="symbol">The type symbol to convert</param>
/// <param name="format">Optional display format settings</param>
/// <returns>A normalized string representation of the type</returns>
public static string ToNormalizedDisplayString(this INamedTypeSymbol symbol, SymbolDisplayFormat? format = null)
{
if (symbol == null)
throw new ArgumentNullException(nameof(symbol));

if (symbol.IsGenericType)
{
var genericType = symbol.ConstructUnboundGenericType();
return genericType.ToDisplayString(format);
}

return symbol.ToDisplayString(format);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed partial class XmlCommentGenerator
cancellationToken: cancellationToken);
if (!string.IsNullOrEmpty(comment) && !string.Equals("<doc />", comment, StringComparison.Ordinal))
{
var typeInfo = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var typeInfo = type.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var typeComment = XmlComment.Parse(comment, new());
comments.Add((typeInfo, null, typeComment));
}
Expand All @@ -46,7 +46,7 @@ public sealed partial class XmlCommentGenerator
cancellationToken: cancellationToken);
if (!string.IsNullOrEmpty(comment) && !string.Equals("<doc />", comment, StringComparison.Ordinal))
{
var typeInfo = property.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var typeInfo = property.ContainingType.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var propertyInfo = property.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var propertyComment = XmlComment.Parse(comment, new());
if (propertyComment is not null)
Expand All @@ -72,7 +72,7 @@ public sealed partial class XmlCommentGenerator
{
continue;
}
var typeInfo = method.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var typeInfo = method.ContainingType.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var methodInfo = method.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
comments.Add((typeInfo, methodInfo, XmlComment.Parse(comment, new())));
}
Expand Down
Loading