From fe1215e7402ac005c201fbfa1bd9753ebee5fedd Mon Sep 17 00:00:00 2001 From: Mike Marynowski Date: Fri, 24 Feb 2023 11:09:47 -0500 Subject: [PATCH 1/2] Add option for including explicit interface implementations --- .../DotnetApiCatalog.cs | 1 + .../ExtractMetadata/ExtractMetadataConfig.cs | 2 ++ .../MetadataJsonItemConfig.cs | 3 +++ .../SymbolFilter.cs | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/src/Microsoft.DocAsCode.Dotnet/DotnetApiCatalog.cs b/src/Microsoft.DocAsCode.Dotnet/DotnetApiCatalog.cs index 2b0e1dd136e..9845154a8d2 100644 --- a/src/Microsoft.DocAsCode.Dotnet/DotnetApiCatalog.cs +++ b/src/Microsoft.DocAsCode.Dotnet/DotnetApiCatalog.cs @@ -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, diff --git a/src/Microsoft.DocAsCode.Dotnet/ExtractMetadata/ExtractMetadataConfig.cs b/src/Microsoft.DocAsCode.Dotnet/ExtractMetadata/ExtractMetadataConfig.cs index c0d05456248..b58245f3a39 100644 --- a/src/Microsoft.DocAsCode.Dotnet/ExtractMetadata/ExtractMetadataConfig.cs +++ b/src/Microsoft.DocAsCode.Dotnet/ExtractMetadata/ExtractMetadataConfig.cs @@ -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; } diff --git a/src/Microsoft.DocAsCode.Dotnet/MetadataJsonItemConfig.cs b/src/Microsoft.DocAsCode.Dotnet/MetadataJsonItemConfig.cs index 01de0e951bb..a2d17ec94d6 100644 --- a/src/Microsoft.DocAsCode.Dotnet/MetadataJsonItemConfig.cs +++ b/src/Microsoft.DocAsCode.Dotnet/MetadataJsonItemConfig.cs @@ -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; } diff --git a/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs b/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs index ea5b1490961..b2d46d2999f 100644 --- a/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs +++ b/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs @@ -94,6 +94,20 @@ private bool IsSymbolAccessible(ISymbol symbol) if (symbol.IsImplicitlyDeclared && symbol.Kind is not SymbolKind.Namespace) return false; + if (_config.IncludeExplicitInterfaceImplementations) + { + bool isEii = symbol.Kind switch + { + SymbolKind.Method => IsEiiAndIncludesContainingSymbols(((IMethodSymbol)symbol).ExplicitInterfaceImplementations), + SymbolKind.Property => IsEiiAndIncludesContainingSymbols(((IPropertySymbol)symbol).ExplicitInterfaceImplementations), + SymbolKind.Event => IsEiiAndIncludesContainingSymbols(((IEventSymbol)symbol).ExplicitInterfaceImplementations), + _ => false, + }; + + if (isEii) + return true; + } + if (_config.IncludePrivateMembers) { return symbol.Kind switch @@ -114,6 +128,11 @@ bool IncludesContainingSymbols(IEnumerable symbols) { return !symbols.Any() || symbols.All(s => IncludeApi(s.ContainingSymbol)); } + + bool IsEiiAndIncludesContainingSymbols(IEnumerable symbols) + { + return symbols.Any() && symbols.All(s => IncludeApi(s.ContainingSymbol)); + } } } } From d0896851f191a8c73ea33df75cebda47a98ff9e8 Mon Sep 17 00:00:00 2001 From: Mike Marynowski Date: Fri, 16 Jun 2023 08:02:34 -0400 Subject: [PATCH 2/2] Refactor out symbol helper for EIIs --- .../SymbolFilter.cs | 24 ++++++------------- .../SymbolHelper.cs | 14 +++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs b/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs index b2d46d2999f..e250f25dcc7 100644 --- a/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs +++ b/src/Microsoft.DocAsCode.Dotnet/SymbolFilter.cs @@ -94,29 +94,19 @@ private bool IsSymbolAccessible(ISymbol symbol) if (symbol.IsImplicitlyDeclared && symbol.Kind is not SymbolKind.Namespace) return false; - if (_config.IncludeExplicitInterfaceImplementations) + if (_config.IncludeExplicitInterfaceImplementations && + SymbolHelper.TryGetExplicitInterfaceImplementations(symbol, out var eiis) && + IsEiiAndIncludesContainingSymbols(eiis)) { - bool isEii = symbol.Kind switch - { - SymbolKind.Method => IsEiiAndIncludesContainingSymbols(((IMethodSymbol)symbol).ExplicitInterfaceImplementations), - SymbolKind.Property => IsEiiAndIncludesContainingSymbols(((IPropertySymbol)symbol).ExplicitInterfaceImplementations), - SymbolKind.Event => IsEiiAndIncludesContainingSymbols(((IEventSymbol)symbol).ExplicitInterfaceImplementations), - _ => false, - }; - - if (isEii) 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) diff --git a/src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs b/src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs index 72923319813..b011a8a90c3 100644 --- a/src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs +++ b/src/Microsoft.DocAsCode.Dotnet/SymbolHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.CodeAnalysis; @@ -83,5 +84,18 @@ public static IEnumerable GetAllNamespaces(this IAssemblySymbo } } } + + public static bool TryGetExplicitInterfaceImplementations(ISymbol symbol, [MaybeNullWhen(false)] out IEnumerable eiis) + { + eiis = symbol.Kind switch + { + SymbolKind.Method => ((IMethodSymbol)symbol).ExplicitInterfaceImplementations, + SymbolKind.Property => ((IPropertySymbol)symbol).ExplicitInterfaceImplementations, + SymbolKind.Event => ((IEventSymbol)symbol).ExplicitInterfaceImplementations, + _ => null, + }; + + return eiis != null; + } } }