Skip to content

Fix generic type handling #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -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
@@ -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));
}
@@ -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)
@@ -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())));
}