Skip to content

[WIP] GenAPI: a work around for a generation an explicit interface implementation indexer. #31628

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

Closed
Closed
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
14 changes: 13 additions & 1 deletion src/GenAPI/Microsoft.DotNet.GenAPI/CSharpFileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,27 @@ private SyntaxNode Visit(SyntaxNode namedTypeNode, INamedTypeSymbol namedType)

foreach (ISymbol member in members.Order())
{
IMethodSymbol? method = member as IMethodSymbol;
// If the method is ExplicitInterfaceImplementation and is derived from an interface that was filtered out, we must filter out it either.
if (member is IMethodSymbol method &&
if (method != null &&
method.MethodKind == MethodKind.ExplicitInterfaceImplementation &&
method.ExplicitInterfaceImplementations.Any(m => !_symbolFilter.Include(m.ContainingSymbol) ||
// if explicit interface implementation method has inaccessible type argument
m.ContainingType.HasInaccessibleTypeArgument(_symbolFilter)))
{
continue;
}

// TODO: a work around for the https://github.com/dotnet/sdk/issues/31570 issue.
// if the symbol is a method and if it is an explicit interface implementation getter or setter of an indexer property (get_Item or set_Item).
if (method != null && method.MethodKind == MethodKind.ExplicitInterfaceImplementation &&
method.ExplicitInterfaceImplementations.Length == 1 &&
method.ExplicitInterfaceImplementations.ElementAt(0) is IMethodSymbol explicitMethod &&
(explicitMethod.MethodKind == MethodKind.PropertyGet || explicitMethod.MethodKind == MethodKind.PropertySet))
{
continue;
}

// If the property is derived from an interface that was filter out, we must filtered out it either.
if (member is IPropertySymbol property && !property.ExplicitInterfaceImplementations.IsEmpty &&
property.ExplicitInterfaceImplementations.Any(m => !_symbolFilter.Include(m.ContainingSymbol)))
Expand Down
10 changes: 10 additions & 0 deletions src/GenAPI/Microsoft.DotNet.GenAPI/SyntaxGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public static SyntaxNode DeclarationExt(this SyntaxGenerator syntaxGenerator, IS
}
}

// TODO: a work around for the https://github.com/dotnet/sdk/issues/31570 issue.
// if the symbol is a property (not an indexer) and if it is an explicit interface implementation of an indexer property.
if (symbol is IPropertySymbol propertySymbol &&
!propertySymbol.IsIndexer && propertySymbol.ExplicitInterfaceImplementations.Length == 1 &&
propertySymbol.ExplicitInterfaceImplementations.ElementAt(0) is IPropertySymbol explicitProperty &&
explicitProperty.IsIndexer)
{
return syntaxGenerator.IndexerDeclaration(propertySymbol);
}

try
{
return syntaxGenerator.Declaration(symbol);
Expand Down