Skip to content
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

Add option for including explicit interface implementations #8446

Closed
wants to merge 2 commits into from
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
1 change: 1 addition & 0 deletions src/Microsoft.DocAsCode.Dotnet/DotnetApiCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig config
ShouldSkipMarkup = configModel?.ShouldSkipMarkup ?? false,
FilterConfigFile = configModel?.FilterConfigFile is null ? null : Path.GetFullPath(Path.Combine(EnvironmentContext.BaseDirectory, configModel.FilterConfigFile)),
IncludePrivateMembers = configModel?.IncludePrivateMembers ?? false,
IncludeExplicitInterfaceImplementations = configModel?.IncludeExplicitInterfaceImplementations ?? false,
GlobalNamespaceId = configModel?.GlobalNamespaceId,
UseCompatibilityFileName = configModel?.UseCompatibilityFileName ?? false,
MSBuildProperties = configModel?.MSBuildProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal class ExtractMetadataConfig

public bool IncludePrivateMembers { get; init; }

public bool IncludeExplicitInterfaceImplementations { get; init; }

public bool UseCompatibilityFileName { get; init; }

public string GlobalNamespaceId { get; init; }
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.DocAsCode.Dotnet/MetadataJsonItemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ internal class MetadataJsonItemConfig
[JsonProperty("includePrivateMembers")]
public bool IncludePrivateMembers { get; set; }

[JsonProperty("includeExplicitInterfaceImplementations")]
public bool IncludeExplicitInterfaceImplementations { get; set; }

[JsonProperty("globalNamespaceId")]
public string GlobalNamespaceId { get; set; }

Expand Down
23 changes: 16 additions & 7 deletions src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ private bool IsSymbolAccessible(ISymbol symbol)
if (symbol.IsImplicitlyDeclared && symbol.Kind is not SymbolKind.Namespace)
return false;

if (_config.IncludeExplicitInterfaceImplementations &&
SymbolHelper.TryGetExplicitInterfaceImplementations(symbol, out var eiis) &&
IsEiiAndIncludesContainingSymbols(eiis))
{
return true;
}

if (_config.IncludePrivateMembers)
{
return symbol.Kind switch
{
SymbolKind.Method => IncludesContainingSymbols(((IMethodSymbol)symbol).ExplicitInterfaceImplementations),
SymbolKind.Property => IncludesContainingSymbols(((IPropertySymbol)symbol).ExplicitInterfaceImplementations),
SymbolKind.Event => IncludesContainingSymbols(((IEventSymbol)symbol).ExplicitInterfaceImplementations),
_ => true,
};
if (SymbolHelper.TryGetExplicitInterfaceImplementations(symbol, out eiis))
return IncludesContainingSymbols(eiis);

return true;
}

if (GetDisplayAccessibility(symbol) is null)
Expand All @@ -114,6 +118,11 @@ bool IncludesContainingSymbols(IEnumerable<ISymbol> symbols)
{
return !symbols.Any() || symbols.All(s => IncludeApi(s.ContainingSymbol));
}

bool IsEiiAndIncludesContainingSymbols(IEnumerable<ISymbol> symbols)
{
return symbols.Any() && symbols.All(s => IncludeApi(s.ContainingSymbol));
}
}
}
}
14 changes: 14 additions & 0 deletions src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis;

Expand Down Expand Up @@ -83,5 +84,18 @@ public static IEnumerable<INamespaceSymbol> GetAllNamespaces(this IAssemblySymbo
}
}
}

public static bool TryGetExplicitInterfaceImplementations(ISymbol symbol, [MaybeNullWhen(false)] out IEnumerable<ISymbol> eiis)
{
eiis = symbol.Kind switch
{
SymbolKind.Method => ((IMethodSymbol)symbol).ExplicitInterfaceImplementations,
SymbolKind.Property => ((IPropertySymbol)symbol).ExplicitInterfaceImplementations,
SymbolKind.Event => ((IEventSymbol)symbol).ExplicitInterfaceImplementations,
_ => null,
};

return eiis != null;
}
}
}