Skip to content

Commit

Permalink
fix: hide generated assembly name (#8637)
Browse files Browse the repository at this point in the history
* fix: hide generated assembly name

* test(snapshot): update snapshots for 116a626

---------

Co-authored-by: yufeih <[email protected]>
  • Loading branch information
yufeih and yufeih authored Apr 12, 2023
1 parent c968e07 commit 2d4f111
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 77 deletions.
20 changes: 10 additions & 10 deletions src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ internal static class CompilationHelper
{
CS.SyntaxFactory.ParseSyntaxTree(
"""
class Bootstrap
{
public static void Main(string[] foo) { }
}
"""),
class Bootstrap
{
public static void Main(string[] foo) { }
}
"""),
};

public static bool CheckDiagnostics(this Compilation compilation, bool errorAsWarning)
Expand Down Expand Up @@ -56,13 +56,13 @@ public static bool CheckDiagnostics(this Compilation compilation, bool errorAsWa
public static Compilation CreateCompilationFromCSharpFiles(IEnumerable<string> files)
{
return CS.CSharpCompilation.Create(
assemblyName: "cs.temp.dll",
assemblyName: null,
options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: XmlFileResolver.Default),
syntaxTrees: files.Select(path => CS.SyntaxFactory.ParseSyntaxTree(File.ReadAllText(path), path: path)),
references: GetDefaultMetadataReferences("C#"));
}

public static Compilation CreateCompilationFromCSharpCode(string code, string name = "cs.temp.dll", params MetadataReference[] references)
public static Compilation CreateCompilationFromCSharpCode(string code, string name = null, params MetadataReference[] references)
{
return CS.CSharpCompilation.Create(
name,
Expand All @@ -74,13 +74,13 @@ public static Compilation CreateCompilationFromCSharpCode(string code, string na
public static Compilation CreateCompilationFromVBFiles(IEnumerable<string> files)
{
return VB.VisualBasicCompilation.Create(
assemblyName: "vb.temp.dll",
assemblyName: null,
options: new VB.VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, globalImports: GetVBGlobalImports(), xmlReferenceResolver: XmlFileResolver.Default),
syntaxTrees: files.Select(path => VB.SyntaxFactory.ParseSyntaxTree(File.ReadAllText(path), path: path)),
references: GetDefaultMetadataReferences("VB"));
}

public static Compilation CreateCompilationFromVBCode(string code, string name = "vb.temp.dll", params MetadataReference[] references)
public static Compilation CreateCompilationFromVBCode(string code, string name = null, params MetadataReference[] references)
{
return VB.VisualBasicCompilation.Create(
name,
Expand All @@ -93,7 +93,7 @@ public static (Compilation, IAssemblySymbol) CreateCompilationFromAssembly(strin
{
var metadataReference = CreateMetadataReference(assemblyPath);
var compilation = CS.CSharpCompilation.Create(
"EmptyProjectWithAssembly",
assemblyName: null,
options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
syntaxTrees: s_assemblyBootstrap,
references: GetReferenceAssemblies(assemblyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override MetadataItem DefaultVisit(ISymbol symbol)
item.DisplayQualifiedNames = new SortedList<SyntaxLanguage, string>();
item.Source = VisitorHelper.GetSourceDetail(symbol, _compilation);
var assemblyName = symbol.ContainingAssembly?.Name;
item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) ? null : new List<string> { assemblyName };
item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) || assemblyName is "?" ? null : new List<string> { assemblyName };
if (symbol is not INamespaceSymbol)
{
var namespaceName = VisitorHelper.GetId(symbol.ContainingNamespace);
Expand Down
2 changes: 1 addition & 1 deletion templates/modern/partials/class.header.tmpl.partial
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div class="facts text-secondary">
<dl><dt>{{__global.namespace}}</dt><dd>{{{namespace.specName.0.value}}}</dd></dl>
<dl><dt>{{__global.assembly}}</dt><dd>{{assemblies.0}}.dll</dd></dl>
{{#assemblies.0}}<dl><dt>{{__global.assembly}}</dt><dd>{{assemblies.0}}.dll</dd></dl>{{/assemblies.0}}
</div>

<div class="markdown summary">{{{summary}}}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": "MyExample",
"overload": {
"uid": "MyExample.ExampleClass.#ctor*",
Expand Down Expand Up @@ -191,9 +188,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "MyExample",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "MyExample",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": "MyExample",
"overload": {
"uid": "MyExample.ExampleClass.MyMethod*",
Expand Down Expand Up @@ -236,9 +233,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "MyExample",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": "MyExample",
"overload": {
"uid": "MyExample.ExampleClass.MyProperty*",
Expand Down Expand Up @@ -238,9 +235,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "MyExample",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "MyExample",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@
}
],
"type": "namespace",
"assemblies": [
"cs.temp.dll"
],
"level": 0.0,
"_systemKeys": [
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": "BuildFromCSharpSourceCode",
"overload": {
"uid": "BuildFromCSharpSourceCode.CSharp.Main*",
Expand Down Expand Up @@ -286,9 +283,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"cs.temp.dll"
],
"namespace": {
"uid": "BuildFromCSharpSourceCode",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@
}
],
"type": "namespace",
"assemblies": [
"cs.temp.dll"
],
"level": 0.0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": "BuildFromVBSourceCode",
"overload": {
"uid": "BuildFromVBSourceCode.BaseClass1.WithDeclarationKeyword*",
Expand Down Expand Up @@ -331,9 +328,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": {
"uid": "BuildFromVBSourceCode",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": "BuildFromVBSourceCode",
"example": [],
"level": 0.0,
Expand Down Expand Up @@ -314,9 +311,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": "BuildFromVBSourceCode",
"overload": {
"uid": "BuildFromVBSourceCode.Class1.Keyword*",
Expand Down Expand Up @@ -565,9 +559,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": "BuildFromVBSourceCode",
"example": [],
"overload": {
Expand Down Expand Up @@ -791,9 +782,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": "BuildFromVBSourceCode",
"example": [],
"overridden": {
Expand Down Expand Up @@ -947,9 +935,6 @@
"endLine": 0.0,
"isExternal": false
},
"assemblies": [
"vb.temp.dll"
],
"namespace": {
"uid": "BuildFromVBSourceCode",
"isEii": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@
}
],
"type": "namespace",
"assemblies": [
"vb.temp.dll"
],
"level": 0.0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"api/BuildFromCSharpSourceCode.CSharp.html": {
"href": "api/BuildFromCSharpSourceCode.CSharp.html",
"title": "Class CSharp | docfx seed website",
"keywords": "Class CSharp Namespace BuildFromCSharpSourceCode Assembly cs.temp.dll.dll public class CSharp Inheritance object CSharp Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods Main(string[]) public static void Main(string[] args) Parameters args string[]"
"keywords": "Class CSharp Namespace BuildFromCSharpSourceCode public class CSharp Inheritance object CSharp Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods Main(string[]) public static void Main(string[] args) Parameters args string[]"
},
"api/BuildFromCSharpSourceCode.html": {
"href": "api/BuildFromCSharpSourceCode.html",
Expand Down Expand Up @@ -82,12 +82,12 @@
"api/BuildFromVBSourceCode.BaseClass1.html": {
"href": "api/BuildFromVBSourceCode.BaseClass1.html",
"title": "Class BaseClass1 | docfx seed website",
"keywords": "Class BaseClass1 Namespace BuildFromVBSourceCode Assembly vb.temp.dll.dll This is the BaseClass public abstract class BaseClass1 Inheritance object BaseClass1 Derived Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.Finalize() object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods WithDeclarationKeyword(Class1) public abstract DateTime WithDeclarationKeyword(Class1 keyword) Parameters keyword Class1 Returns DateTime"
"keywords": "Class BaseClass1 Namespace BuildFromVBSourceCode This is the BaseClass public abstract class BaseClass1 Inheritance object BaseClass1 Derived Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.Finalize() object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Methods WithDeclarationKeyword(Class1) public abstract DateTime WithDeclarationKeyword(Class1 keyword) Parameters keyword Class1 Returns DateTime"
},
"api/BuildFromVBSourceCode.Class1.html": {
"href": "api/BuildFromVBSourceCode.Class1.html",
"title": "Class Class1 | docfx seed website",
"keywords": "Class Class1 Namespace BuildFromVBSourceCode Assembly vb.temp.dll.dll This is summary from vb class... public class Class1 : BaseClass1 Inheritance object BaseClass1 Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.Finalize() object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Fields ValueClass This is a Value type public Class1 ValueClass Field Value Class1 Properties Keyword [Obsolete(\"This member is obsolete.\", true)] public Class1 Keyword { get; } Property Value Class1 Methods Value(string) This is a Function public int Value(string name) Parameters name string Name as the String value Returns int Returns Ahooo WithDeclarationKeyword(Class1) What is Sub? public override DateTime WithDeclarationKeyword(Class1 keyword) Parameters keyword Class1 Returns DateTime"
"keywords": "Class Class1 Namespace BuildFromVBSourceCode This is summary from vb class... public class Class1 : BaseClass1 Inheritance object BaseClass1 Class1 Inherited Members object.Equals(object) object.Equals(object, object) object.Finalize() object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString() Fields ValueClass This is a Value type public Class1 ValueClass Field Value Class1 Properties Keyword [Obsolete(\"This member is obsolete.\", true)] public Class1 Keyword { get; } Property Value Class1 Methods Value(string) This is a Function public int Value(string name) Parameters name string Name as the String value Returns int Returns Ahooo WithDeclarationKeyword(Class1) What is Sub? public override DateTime WithDeclarationKeyword(Class1 keyword) Parameters keyword Class1 Returns DateTime"
},
"api/BuildFromVBSourceCode.html": {
"href": "api/BuildFromVBSourceCode.html",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ <h1 id="BuildFromProject_Class1" data-uid="BuildFromProject.Class1" class="text-

<div class="facts text-secondary">
<dl><dt>Namespace</dt><dd><a class="xref" href="BuildFromProject.html">Build<wbr>From<wbr>Project</a></dd></dl>
<dl><dt>Assembly</dt><dd>BuildFromProject.dll</dd></dl>
<dl><dt>Assembly</dt><dd>BuildFromProject.dll</dd></dl>
</div>

<div class="markdown summary"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ <h1 id="CatLibrary_Cat_2" data-uid="CatLibrary.Cat`2" class="text-break">

<div class="facts text-secondary">
<dl><dt>Namespace</dt><dd><a class="xref" href="CatLibrary.html">Cat<wbr>Library</a></dd></dl>
<dl><dt>Assembly</dt><dd>CatLibrary.dll</dd></dl>
<dl><dt>Assembly</dt><dd>CatLibrary.dll</dd></dl>
</div>

<div class="markdown summary"><p>Here's main class of this <i>Demo</i>.</p>
Expand Down

0 comments on commit 2d4f111

Please sign in to comment.