From 84ffe213c72ef8603eb2802f81623a5b8a5eb030 Mon Sep 17 00:00:00 2001 From: Laszlo Paillat Date: Mon, 14 Oct 2024 19:01:42 +0200 Subject: [PATCH] fixed enum fields to respect code order (fixes #131) --- documentation/NEXT_RELEASENOTES.txt | 3 ++- .../Sections/ChildrenSection.cs | 6 ++++++ source/DefaultDocumentation.Test/AssemblyInfo.cs | 4 +++- .../Sections/EnumFieldsSectionTests/WriteShould.cs | 7 ++++++- .../Sections/ParametersSectionTests/WriteShould.cs | 2 +- .../Markdown/Sections/TitleSectionTests/WriteShould.cs | 4 ++-- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/documentation/NEXT_RELEASENOTES.txt b/documentation/NEXT_RELEASENOTES.txt index 01a7d9e5..82382233 100644 --- a/documentation/NEXT_RELEASENOTES.txt +++ b/documentation/NEXT_RELEASENOTES.txt @@ -16,4 +16,5 @@ - fixed property getter/setter access modifier not taken into account (fixes #151) - fixed markdown special characters not escaped (fixes #117) - fixed unhandled xml elements not rendering as is in markdown (fixes #126) -- fixed issue with list rendering \ No newline at end of file +- fixed issue with list rendering +- fixed enum fields to respect code order (fixes #131) \ No newline at end of file diff --git a/source/DefaultDocumentation.Markdown/Sections/ChildrenSection.cs b/source/DefaultDocumentation.Markdown/Sections/ChildrenSection.cs index 88a81d32..126a3cb4 100644 --- a/source/DefaultDocumentation.Markdown/Sections/ChildrenSection.cs +++ b/source/DefaultDocumentation.Markdown/Sections/ChildrenSection.cs @@ -156,6 +156,12 @@ public sealed class EnumFieldsSection : ChildrenSection public EnumFieldsSection() : base(ConfigName, "### Fields") { } + + /// + protected override IEnumerable? GetChildren(IGeneralContext context, DocItem item) + => item is EnumDocItem enumType + ? base.GetChildren(context, item).OrderBy(child => enumType.Type.Fields.TakeWhile(field => field != child.Field).Count()) + : []; } /// diff --git a/source/DefaultDocumentation.Test/AssemblyInfo.cs b/source/DefaultDocumentation.Test/AssemblyInfo.cs index a4a3509c..efa522b0 100644 --- a/source/DefaultDocumentation.Test/AssemblyInfo.cs +++ b/source/DefaultDocumentation.Test/AssemblyInfo.cs @@ -26,7 +26,8 @@ public sealed class AssemblyInfo : AssemblyInfo.IInterface, IEnumerator private enum Enum { Value, - ValueWithConstant = 42 + ValueWithConstant = 42, + AnotherValue } private enum ShortEnum : short @@ -143,6 +144,7 @@ void IInterface.Method() public static readonly EnumDocItem EnumDocItem = new(ClassDocItem, Get($"T:{typeof(Enum).FullName}"), null); public static readonly EnumFieldDocItem EnumFieldDocItem = new(EnumDocItem, Get($"F:{typeof(Enum).FullName}.{nameof(Enum.Value)}"), null); public static readonly EnumFieldDocItem EnumFieldWithConstantDocItem = new(EnumDocItem, Get($"F:{typeof(Enum).FullName}.{nameof(Enum.ValueWithConstant)}"), null); + public static readonly EnumFieldDocItem AnotherEnumFieldDocItem = new(EnumDocItem, Get($"F:{typeof(Enum).FullName}.{nameof(Enum.AnotherValue)}"), null); public static readonly EnumDocItem ShortEnumDocItem = new(ClassDocItem, Get($"T:{typeof(ShortEnum).FullName}"), null); diff --git a/source/DefaultDocumentation.Test/Markdown/Sections/EnumFieldsSectionTests/WriteShould.cs b/source/DefaultDocumentation.Test/Markdown/Sections/EnumFieldsSectionTests/WriteShould.cs index 457b1398..e8c1d3eb 100644 --- a/source/DefaultDocumentation.Test/Markdown/Sections/EnumFieldsSectionTests/WriteShould.cs +++ b/source/DefaultDocumentation.Test/Markdown/Sections/EnumFieldsSectionTests/WriteShould.cs @@ -13,6 +13,7 @@ protected override IReadOnlyDictionary GetItems() => AssemblyInfo.EnumDocItem.IntoEnumerable() .Concat(AssemblyInfo.EnumFieldDocItem) .Concat(AssemblyInfo.EnumFieldWithConstantDocItem) + .Concat(AssemblyInfo.AnotherEnumFieldDocItem) .ToDictionary(item => item.Id); protected override IUrlFactory[] GetUrlFactories() @@ -36,5 +37,9 @@ public void WriteWhenEnumDocItem() => Test( -`ValueWithConstant` 42"); +`ValueWithConstant` 42 + + + +`AnotherValue` 43"); } diff --git a/source/DefaultDocumentation.Test/Markdown/Sections/ParametersSectionTests/WriteShould.cs b/source/DefaultDocumentation.Test/Markdown/Sections/ParametersSectionTests/WriteShould.cs index ad673e2d..d367c7bd 100644 --- a/source/DefaultDocumentation.Test/Markdown/Sections/ParametersSectionTests/WriteShould.cs +++ b/source/DefaultDocumentation.Test/Markdown/Sections/ParametersSectionTests/WriteShould.cs @@ -12,7 +12,7 @@ public sealed class WriteShould : BaseSectionTester protected override IReadOnlyDictionary GetItems() => AssemblyInfo.MethodWithParameterDocItem.Parameters.AsEnumerable() .Concat(AssemblyInfo.OperatorDocItem.Parameters) - .Concat(Enumerable.Repeat(AssemblyInfo.ClassDocItem, 1)) + .Concat(AssemblyInfo.ClassDocItem) .ToDictionary(item => item.Id); protected override IUrlFactory[] GetUrlFactories() => [new DocItemFactory()]; diff --git a/source/DefaultDocumentation.Test/Markdown/Sections/TitleSectionTests/WriteShould.cs b/source/DefaultDocumentation.Test/Markdown/Sections/TitleSectionTests/WriteShould.cs index 91352b14..e8616f7f 100644 --- a/source/DefaultDocumentation.Test/Markdown/Sections/TitleSectionTests/WriteShould.cs +++ b/source/DefaultDocumentation.Test/Markdown/Sections/TitleSectionTests/WriteShould.cs @@ -15,8 +15,8 @@ protected override IReadOnlyDictionary GetItems() => AssemblyInfo.MethodWithParameterDocItem.Parameters .AsEnumerable() .Concat(AssemblyInfo.ClassWithTypeParameterDocItem.TypeParameters) - .Concat(Enumerable.Repeat(AssemblyInfo.EnumFieldDocItem, 1)) - .Concat(Enumerable.Repeat(AssemblyInfo.EnumFieldWithConstantDocItem, 1)) + .Concat(AssemblyInfo.EnumFieldDocItem) + .Concat(AssemblyInfo.EnumFieldWithConstantDocItem) .ToDictionary(item => item.Id); protected override GeneratedPages GetGeneratedPages()