-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles DE VANDIERE
committed
Nov 20, 2019
1 parent
b1b3361
commit 6632276
Showing
7 changed files
with
116 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
# XMLDoc2Markdown | ||
|
||
Tool to generate markdown from C# XML documentation, based on [MarkdownGenerator](https://github.com/neuecc/MarkdownGenerator) project. | ||
|
||
See generated sample documentation [here](sample). | ||
|
||
## How to use | ||
|
||
### Install tool | ||
|
||
```shell | ||
> dotnet tool install -g XMLDoc2Markdown | ||
``` | ||
|
||
### Generate documentation | ||
|
||
```shell | ||
> xmldoc2md <DLL_SOURCE_PATH> <OUTPUT_DIRECTORY> | ||
``` | ||
|
||
#### Example | ||
|
||
```shell | ||
> xmldoc2md Sample.dll docs | ||
``` | ||
|
||
### Display command line help | ||
|
||
```shell | ||
> xmldoc2md -h | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# References | ||
# MyClassLib | ||
|
||
## MyClassLib | ||
## `MyClassLib` | ||
|
||
- [`Class1`](MyClassLib/Class1) | ||
|
||
## MyClassLib.SubNamespace | ||
## `MyClassLib.SubNamespace` | ||
|
||
- [`GenericClass<T>`](MyClassLib.SubNamespace/GenericClass{T}) | ||
- [`SubClass`](MyClassLib.SubNamespace/SubClass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dotnet publish .\sample\MyClassLib\MyClassLib.csproj -c Release -o publish | ||
dotnet run -p .\src\XMLDoc2Markdown\XMLDoc2Markdown.csproj .\publish\MyClassLib.dll .\docs\sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
|
||
namespace XMLDoc2Markdown | ||
{ | ||
public class XmlDocumentation | ||
{ | ||
public string AssemblyName { get; private set; } | ||
public IEnumerable<MarkdownableType> Types { get; private set; } | ||
|
||
public XmlDocumentation(string dllPath, string namespaceMatch) | ||
{ | ||
Assembly assembly = Assembly.LoadFrom(dllPath); | ||
|
||
this.AssemblyName = assembly.GetName().Name; | ||
|
||
var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml"); | ||
|
||
XmlDocumentComment[] comments = new XmlDocumentComment[0]; | ||
if (File.Exists(xmlPath)) | ||
{ | ||
comments = VSDocParser.ParseXmlComment(XDocument.Parse(File.ReadAllText(xmlPath)), namespaceMatch); | ||
} | ||
var commentsLookup = comments.ToLookup(x => x.ClassName); | ||
|
||
var namespaceRegex = | ||
!string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null; | ||
|
||
var markdownableTypes = new[] { assembly } | ||
.SelectMany(x => | ||
{ | ||
try | ||
{ | ||
return x.GetTypes(); | ||
} | ||
catch (ReflectionTypeLoadException ex) | ||
{ | ||
return ex.Types.Where(t => t != null); | ||
} | ||
catch | ||
{ | ||
return Type.EmptyTypes; | ||
} | ||
}) | ||
.Where(x => x != null) | ||
.Where(x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) && !x.GetCustomAttributes<ObsoleteAttribute>().Any()) | ||
.Where(x => IsRequiredNamespace(x, namespaceRegex)) | ||
.Select(x => new MarkdownableType(x, commentsLookup)) | ||
.ToArray(); | ||
|
||
this.Types = markdownableTypes; | ||
} | ||
|
||
static bool IsRequiredNamespace(Type type, Regex regex) | ||
{ | ||
if (regex == null) | ||
{ | ||
return true; | ||
} | ||
return regex.IsMatch(type.Namespace != null ? type.Namespace : string.Empty); | ||
} | ||
} | ||
} |