Skip to content

Commit

Permalink
implement doc comments for enum value because inheriting from symbol …
Browse files Browse the repository at this point in the history
…base is not desired
  • Loading branch information
Curtis Keller committed Mar 29, 2024
1 parent 502b90e commit e02dfaf
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NTypewriter.CodeModel.Roslyn/EnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class EnumValue : IEnumValue
public object Value => symbol.ConstantValue;
public string Name => symbol.Name;
public IEnumerable<IAttribute> Attributes => AttributeCollection.Create(symbol);

public IDocumentationCommentXml DocComment => DocumentationCommentXml.Create(symbol);

private EnumValue(IFieldSymbol symbol)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
One
Two
Three
This is the number four. (4)Four
This is the number five. (5)Five
25 changes: 25 additions & 0 deletions NTypewriter.CodeModel.Tests/EnumValue/DocComments/inputCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace NTypewriter.Tests.CodeModel
{
enum EnumWithDocComments
{
One = 1,
Two = 2,
Three = 3,
/// <summary>
/// This is the number four. (4)
/// </summary>
Four = 4,
/// <summary>
/// This is the number five. (5)
/// </summary>
Five = 5,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- capture captured
for enum in data.Enums | Symbols.WhereNamespaceStartsWith "NTypewriter.Tests.CodeModel"
for enumValue in enum.Values }}
{{- if enumValue.DocComment && enumValue.DocComment.Summary }}
{{- enumValue.DocComment.Summary }}
{{- end }}
{{- enumValue.Name }}
{{ end
end
end
Save captured "result" }}
6 changes: 6 additions & 0 deletions NTypewriter.CodeModel.Tests/EnumValue/EnumRenderingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public async Task Attributes()
{
await RunTestForProperty();
}

[TestMethod]
public async Task DocComments()
{
await RunTestForProperty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<Compile Remove="DocumentationCommentXml\Returns\inputCode.cs" />
<Compile Remove="DocumentationCommentXml\Summary\inputCode.cs" />
<Compile Remove="EnumValue\Attributes\inputCode.cs" />
<Compile Remove="EnumValue\DocComments\inputCode.cs" />
<Compile Remove="Enum\UnderlyingType\inputCode.cs" />
<Compile Remove="Enum\Values\inputCode.cs" />
<Compile Remove="Event\Type\inputCode.cs" />
Expand Down Expand Up @@ -117,6 +118,8 @@
<None Remove="DocumentationCommentXml\Summary\inputTemplate.tsnt" />
<None Remove="EnumValue\Attributes\expectedResult.txt" />
<None Remove="EnumValue\Attributes\inputTemplate.tsnt" />
<None Remove="EnumValue\DocComments\expectedResult.txt" />
<None Remove="EnumValue\DocComments\inputTemplate.tsnt" />
<None Remove="Enum\UnderlyingType\expectedResult.txt" />
<None Remove="Enum\UnderlyingType\inputTemplate.tsnt" />
<None Remove="Enum\Values\expectedResult.txt" />
Expand Down Expand Up @@ -283,6 +286,9 @@
<EmbeddedResource Include="EnumValue\Attributes\expectedResult.txt" />
<EmbeddedResource Include="EnumValue\Attributes\inputCode.cs" />
<EmbeddedResource Include="EnumValue\Attributes\inputTemplate.tsnt" />
<EmbeddedResource Include="EnumValue\DocComments\expectedResult.txt" />
<EmbeddedResource Include="EnumValue\DocComments\inputCode.cs" />
<EmbeddedResource Include="EnumValue\DocComments\inputTemplate.tsnt" />
<EmbeddedResource Include="Enum\UnderlyingType\expectedResult.txt" />
<EmbeddedResource Include="Enum\UnderlyingType\inputCode.cs" />
<EmbeddedResource Include="Enum\UnderlyingType\inputTemplate.tsnt" />
Expand Down
5 changes: 5 additions & 0 deletions NTypewriter.CodeModel/IEnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ public interface IEnumValue
/// All attributes declared on the enum value.
/// </summary>
IEnumerable<IAttribute> Attributes { get; }

/// <summary>
/// The XML documentation for the comment associated with the symbol.
/// </summary>
IDocumentationCommentXml DocComment { get; }
}
}

0 comments on commit e02dfaf

Please sign in to comment.