Skip to content

Commit 7190dcb

Browse files
Patrick8639p-kostov
authored andcommitted
Feat/private symbols (dotnet#9972)
* (fix): when specifying "includePrivateMembers":"true" in the docfx.json file, enumerates all the private members of the classes. Todo: - remove class constructor; - remove compiler generated members. * Removes class constructors and compiler generated members. * - Use a named parameter to specify the import options. - Refactoring the parameter to directly pass a boolean value.
1 parent 026581a commit 7190dcb

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/Docfx.Dotnet/CompilationHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
45
using Docfx.Common;
56
using Docfx.Exceptions;
67
using ICSharpCode.Decompiler.Metadata;
@@ -102,12 +103,17 @@ public static Compilation CreateCompilationFromVBCode(string code, IDictionary<s
102103
references: GetDefaultMetadataReferences("VB").Concat(references ?? []));
103104
}
104105

105-
public static (Compilation, IAssemblySymbol) CreateCompilationFromAssembly(string assemblyPath, params MetadataReference[] references)
106+
public static (Compilation, IAssemblySymbol) CreateCompilationFromAssembly(string assemblyPath, bool includePrivateMembers = false, params MetadataReference[] references)
106107
{
107108
var metadataReference = CreateMetadataReference(assemblyPath);
108109
var compilation = CS.CSharpCompilation.Create(
109110
assemblyName: null,
110-
options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
111+
options: new CS.CSharpCompilationOptions(
112+
outputKind : OutputKind.DynamicallyLinkedLibrary,
113+
metadataImportOptions : includePrivateMembers
114+
? MetadataImportOptions.All
115+
: MetadataImportOptions.Public
116+
),
111117
syntaxTrees: s_assemblyBootstrap,
112118
references: GetReferenceAssemblies(assemblyPath)
113119
.Select(CreateMetadataReference)

src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ await LoadCompilationFromProject(project.AbsolutePath) is { } compilation)
117117
foreach (var assemblyFile in assemblyFiles)
118118
{
119119
Logger.LogInfo($"Loading assembly {assemblyFile.NormalizedPath}");
120-
var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly(assemblyFile.NormalizedPath, metadataReferences);
120+
var (compilation, assembly) = CompilationHelper.CreateCompilationFromAssembly(assemblyFile.NormalizedPath, config.IncludePrivateMembers, metadataReferences);
121121
hasCompilationError |= compilation.CheckDiagnostics(config.AllowCompilationErrors);
122122
assemblies.Add((assembly, compilation));
123123
}

src/Docfx.Dotnet/ManagedReference/Visitors/SymbolVisitorAdapter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,13 @@ public override MetadataItem VisitNamedType(INamedTypeSymbol symbol)
181181
}
182182

183183
item.Items = new List<MetadataItem>();
184-
foreach (var member in symbol.GetMembers().Where(s => s is not INamedTypeSymbol))
184+
foreach (
185+
var member in symbol.GetMembers()
186+
.Where(static s =>
187+
s is not INamedTypeSymbol
188+
&& ! s.Name.StartsWith('<')
189+
&& (s is not IMethodSymbol ms || ms.MethodKind != MethodKind.StaticConstructor)
190+
))
185191
{
186192
var memberItem = member.Accept(this);
187193
if (memberItem != null)

0 commit comments

Comments
 (0)