Skip to content

Commit

Permalink
fixed enum fields to respect code order (fixes #131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doraku committed Oct 14, 2024
1 parent f2a5aaf commit 84ffe21
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion documentation/NEXT_RELEASENOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
- fixed issue with list rendering
- fixed enum fields to respect code order (fixes #131)
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ public sealed class EnumFieldsSection : ChildrenSection<EnumFieldDocItem>
public EnumFieldsSection()
: base(ConfigName, "### Fields")
{ }

/// <inheritdoc/>
protected override IEnumerable<EnumFieldDocItem>? GetChildren(IGeneralContext context, DocItem item)
=> item is EnumDocItem enumType
? base.GetChildren(context, item).OrderBy(child => enumType.Type.Fields.TakeWhile(field => field != child.Field).Count())
: [];
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion source/DefaultDocumentation.Test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public sealed class AssemblyInfo : AssemblyInfo.IInterface, IEnumerator
private enum Enum
{
Value,
ValueWithConstant = 42
ValueWithConstant = 42,
AnotherValue
}

private enum ShortEnum : short
Expand Down Expand Up @@ -143,6 +144,7 @@ void IInterface.Method()
public static readonly EnumDocItem EnumDocItem = new(ClassDocItem, Get<ITypeDefinition>($"T:{typeof(Enum).FullName}"), null);
public static readonly EnumFieldDocItem EnumFieldDocItem = new(EnumDocItem, Get<IField>($"F:{typeof(Enum).FullName}.{nameof(Enum.Value)}"), null);
public static readonly EnumFieldDocItem EnumFieldWithConstantDocItem = new(EnumDocItem, Get<IField>($"F:{typeof(Enum).FullName}.{nameof(Enum.ValueWithConstant)}"), null);
public static readonly EnumFieldDocItem AnotherEnumFieldDocItem = new(EnumDocItem, Get<IField>($"F:{typeof(Enum).FullName}.{nameof(Enum.AnotherValue)}"), null);

public static readonly EnumDocItem ShortEnumDocItem = new(ClassDocItem, Get<ITypeDefinition>($"T:{typeof(ShortEnum).FullName}"), null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected override IReadOnlyDictionary<string, DocItem> GetItems()
=> AssemblyInfo.EnumDocItem.IntoEnumerable<DocItem>()
.Concat(AssemblyInfo.EnumFieldDocItem)
.Concat(AssemblyInfo.EnumFieldWithConstantDocItem)
.Concat(AssemblyInfo.AnotherEnumFieldDocItem)
.ToDictionary(item => item.Id);

protected override IUrlFactory[] GetUrlFactories()
Expand All @@ -36,5 +37,9 @@ public void WriteWhenEnumDocItem() => Test(
<a name='DefaultDocumentation.AssemblyInfo.Enum.ValueWithConstant'></a>
`ValueWithConstant` 42");
`ValueWithConstant` 42
<a name='DefaultDocumentation.AssemblyInfo.Enum.AnotherValue'></a>
`AnotherValue` 43");
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class WriteShould : BaseSectionTester<ParametersSection>
protected override IReadOnlyDictionary<string, DocItem> GetItems()
=> AssemblyInfo.MethodWithParameterDocItem.Parameters.AsEnumerable<DocItem>()
.Concat(AssemblyInfo.OperatorDocItem.Parameters)
.Concat(Enumerable.Repeat(AssemblyInfo.ClassDocItem, 1))
.Concat(AssemblyInfo.ClassDocItem)
.ToDictionary(item => item.Id);

protected override IUrlFactory[] GetUrlFactories() => [new DocItemFactory()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ protected override IReadOnlyDictionary<string, DocItem> GetItems()
=> AssemblyInfo.MethodWithParameterDocItem.Parameters
.AsEnumerable<DocItem>()
.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()
Expand Down

0 comments on commit 84ffe21

Please sign in to comment.