Skip to content

Commit

Permalink
class library generation concept
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 5, 2024
1 parent 70f08ff commit 94a83a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
45 changes: 40 additions & 5 deletions src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Doki.Output.ClassLibrary;
using System.Text;

namespace Doki.Output.ClassLibrary;

public sealed class ClassLibraryOutput(ClassLibraryOutputOptions options) : IOutput
{
public Task BeginAsync(CancellationToken cancellationToken = default)
public async Task BeginAsync(CancellationToken cancellationToken = default)
{
options.ClearOutputDirectoryIfRequired();

Expand Down Expand Up @@ -34,18 +36,51 @@ public Task BeginAsync(CancellationToken cancellationToken = default)
</Project>
""";

File.WriteAllText(projectFilePath, projectFileContent);

return Task.CompletedTask;
await File.WriteAllTextAsync(projectFilePath, projectFileContent, cancellationToken);
}

public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(contentList);

var contentListFilePath = Path.Combine(options.OutputDirectory.FullName, "Documentation.cs");

var contentListContent = new StringBuilder($$"""
using Doki;
namespace {{options.Namespace}};
public static class Documentation
{
public static readonly AssemblyDocumentation[] Assemblies =
[
""");

foreach (var item in contentList.Items)
{
if (item is not AssemblyDocumentation assemblyDocumentation) continue;

BuildAssemblyDocumentation(assemblyDocumentation, contentListContent);
}

contentListContent.Append("""
];
}
""");

await File.WriteAllTextAsync(contentListFilePath, contentListContent.ToString(), cancellationToken);
}

public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(typeDocumentation);
}

private static void BuildAssemblyDocumentation(AssemblyDocumentation assemblyDocumentation,
StringBuilder contentListContent)
{
// contentListContent.Append($"""
// public static
// """);
}
}
4 changes: 2 additions & 2 deletions src/Doki/DocumentationGenerator.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Doki;

public partial class DocumentationGenerator
{
private static readonly BindingFlags AllMembersBindingFlags = BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Static;
private const BindingFlags AllMembersBindingFlags =
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;

private IEnumerable<DocumentationObject> BuildXmlDocumentation(string xpath, XPathNavigator? typeXml,
DocumentationObject parent)
Expand Down

0 comments on commit 94a83a2

Please sign in to comment.