Migrated Documentation library from NetFlow.DocumentationHelper.Library
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
|
||||
namespace OmegaLeo.HelperLib.Changelog.Attributes
|
||||
{
|
||||
[Changelog("v1.0.0", "Created ChangelogAttribute to be used to register changes in the code.")]
|
||||
[Documentation(nameof(ChangelogAttribute), "Attribute to annotate classes, methods, or properties with changelog information.")]
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
|
||||
public class ChangelogAttribute : Attribute
|
||||
{
|
||||
public string Version { get; }
|
||||
public string Description { get; }
|
||||
|
||||
public ChangelogAttribute(string version, string description)
|
||||
{
|
||||
Version = version;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Changelog
|
||||
|
||||
## Version v1.0.0
|
||||
## Version 1.0.0
|
||||
|
||||
- **Class: ChangelogTool**: Created the class ChangelogTool to extract changelogs via attributes
|
||||
- **Class: ChangelogAttribute**: Created ChangelogAttribute to be used to register changes in the code.
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace OmegaLeo.HelperLib.Changelog.Helpers
|
||||
{
|
||||
[Documentation(nameof(ChangelogHelper),
|
||||
"Helper class to generate changelog markdown from ChangelogAttributes in the provided Assemblies.")]
|
||||
[Changelog("1.2.0", "Created ChangelogHelper to generate markdown from changelog attributes.")]
|
||||
public static class ChangelogHelper
|
||||
{
|
||||
[Documentation(nameof(GetChangelogMarkdown),
|
||||
"Generates a markdown formatted changelog from the changelog attributes in the provided assemblies.")]
|
||||
public static string GetChangelogMarkdown(IEnumerable<Assembly> assemblies)
|
||||
{
|
||||
var changelog = new StringBuilder();
|
||||
var entriesByVersionDate =
|
||||
new Dictionary<(string Version, string Date),
|
||||
Dictionary<string, List<(string ClassName, string Description)>>>();
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
// Get type-level changelog attributes
|
||||
var typeAttrs = type.GetCustomAttributes<ChangelogAttribute>().ToList();
|
||||
|
||||
// Get member-level changelog attributes (methods, properties, fields, etc.)
|
||||
var memberAttrs = type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic |
|
||||
BindingFlags.Static | BindingFlags.Instance)
|
||||
.SelectMany(m => m.GetCustomAttributes<ChangelogAttribute>()
|
||||
.Select(attr => (Member: m, Attribute: attr)))
|
||||
.ToList();
|
||||
|
||||
if (typeAttrs.Any() || memberAttrs.Any())
|
||||
{
|
||||
var namespaceName = type.Namespace ?? "Global";
|
||||
var className = type.Name.Split('`')[0];
|
||||
|
||||
// Process type-level attributes
|
||||
foreach (var attr in typeAttrs)
|
||||
{
|
||||
AddEntry(entriesByVersionDate, namespaceName, className, attr.Version, attr.Date,
|
||||
attr.Description);
|
||||
}
|
||||
|
||||
// Process member-level attributes
|
||||
foreach (var (member, attr) in memberAttrs)
|
||||
{
|
||||
var memberName = $"{className}.{member.Name}";
|
||||
AddEntry(entriesByVersionDate, namespaceName, memberName, attr.Version, attr.Date,
|
||||
attr.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ReflectionTypeLoadException)
|
||||
{
|
||||
// Skip assemblies that can't be fully loaded
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var versionGroup in entriesByVersionDate.OrderByDescending(x => x.Key.Version))
|
||||
{
|
||||
changelog.AppendLine($"## Version {versionGroup.Key.Version}");
|
||||
if (!string.IsNullOrEmpty(versionGroup.Key.Date))
|
||||
{
|
||||
changelog.AppendLine($"### {versionGroup.Key.Date}");
|
||||
}
|
||||
|
||||
changelog.AppendLine();
|
||||
|
||||
foreach (var namespaceGroup in versionGroup.Value.OrderBy(x => x.Key))
|
||||
{
|
||||
changelog.AppendLine($"**{namespaceGroup.Key}**");
|
||||
foreach (var entry in namespaceGroup.Value.OrderBy(x => x.ClassName))
|
||||
{
|
||||
changelog.AppendLine($@"- **{entry.ClassName}**:
|
||||
- {entry.Description}");
|
||||
}
|
||||
|
||||
changelog.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
return changelog.ToString();
|
||||
}
|
||||
|
||||
private static void AddEntry(
|
||||
Dictionary<(string Version, string Date), Dictionary<string, List<(string ClassName, string Description)>>>
|
||||
entriesByVersionDate,
|
||||
string namespaceName,
|
||||
string className,
|
||||
string version,
|
||||
string date,
|
||||
string description)
|
||||
{
|
||||
var key = (version, date ?? string.Empty);
|
||||
|
||||
if (!entriesByVersionDate.ContainsKey(key))
|
||||
entriesByVersionDate[key] = new Dictionary<string, List<(string, string)>>();
|
||||
|
||||
if (!entriesByVersionDate[key].ContainsKey(namespaceName))
|
||||
entriesByVersionDate[key][namespaceName] = new List<(string, string)>();
|
||||
|
||||
entriesByVersionDate[key][namespaceName].Add((className, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+4
-7
@@ -23,17 +23,14 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="NetFlow.DocumentationHelper.Library">
|
||||
<HintPath>..\..\..\..\..\..\home\omegaleo\.nuget\packages\netflow.documentationhelper.library\1.1.2\lib\netstandard2.1\NetFlow.DocumentationHelper.Library.dll</HintPath>
|
||||
<Reference Include="OmegaLeo.HelperLib.Documentation">
|
||||
<HintPath>..\..\..\..\..\..\home\omegaleo\.nuget\packages\OmegaLeo.HelperLib.Documentation\1.1.2\lib\netstandard2.1\OmegaLeo.HelperLib.Documentation.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2" />
|
||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Documentation\OmegaLeo.HelperLib.Documentation.csproj" />
|
||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Shared\OmegaLeo.HelperLib.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Regular → Executable
+1
-1
@@ -3,7 +3,7 @@ Package to help with Changelog generation by providing a new Changelog attribute
|
||||
|
||||
Example attribute usage:
|
||||
```cs
|
||||
[Changelog("v1.0.0", "This is a test")]
|
||||
[Changelog("1.0.0", "This is a test")]
|
||||
[Changelog("v1.0.1", "This is another test")]
|
||||
public class Test
|
||||
{
|
||||
|
||||
Regular → Executable
+2
-3
@@ -2,12 +2,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
using OmegaLeo.HelperLib.Changelog.Attributes;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace OmegaLeo.HelperLib.Changelog.Tools
|
||||
{
|
||||
[Changelog("v1.0.0", "Created the class ChangelogTool to extract changelogs via attributes")]
|
||||
[Changelog("1.0.0", "Created the class ChangelogTool to extract changelogs via attributes")]
|
||||
[Documentation("ChangelogTool", "Provides methods to extract changelog information from assembly attributes.")]
|
||||
public class ChangelogTool
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user