Skip to content

Commit

Permalink
feat: Add DocumentationRemarks as a target for the XmlParser to store…
Browse files Browse the repository at this point in the history
… the <remarks /> section from the XmlDoc. Include tests which also document the need for a <summary /> or <inheritdoc /> section to access it via GetDocumentationMember(). This is mainly to keep backward compatibility with the currently emitted code. reinforced#290
  • Loading branch information
smkanadl committed Jan 12, 2025
1 parent e828362 commit e730d68
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Threading.Tasks;
using Reinforced.Typings.Fluent;
using Xunit;

namespace Reinforced.Typings.Tests.SpecificCases
{
public partial class SpecificTestCases
{
/// <summary>
/// dummy
/// </summary>
/// <remarks>
/// Class remark.
/// </remarks>
public class SomeClassWithRemarks
{
/// <summary>
/// dummy
/// </summary>
/// <remarks>
/// Ctor remark.
/// </remarks>
public SomeClassWithRemarks() { }

/// <inheritdoc cref="SomeClassWithDocs"/>
/// <remarks>
/// Property remark.
/// </remarks>
public string ClassProp { get; set; }

/// <inheritdoc cref="SomeClassWithDocs"/>
/// <remarks>
/// Method remark.
/// </remarks>
public void Method() { }
}

[Fact]
public void RemarksParsedFromDocs()
{
const string result = @"
module Reinforced.Typings.Tests.SpecificCases {
/** dummy */
export class SomeClassWithRemarks
{
/**
* @inheritdoc
*/
public ClassProp: string;
/**
* @inheritdoc
*/
public Method() : void { }
}
}";
AssertConfiguration(
s =>
{
s.TryLookupDocumentationForAssembly(typeof(SpecificTestCases).Assembly);
s.ExportAsClass<SomeClassWithRemarks>()
.WithPublicProperties()
.WithPublicMethods();
},
result,
expAction =>
{
// Currently the <remarks /> are just parsed into the DocumentationMember
// but not used in the generated typings. Hence we use the action on
// the ExportContext to perform the actual test.
// To avoid surprises like empty docs <remarks /> are currently only valid
// if there is a <summar /> or <inheritdoc /> tag.

var type = typeof(SomeClassWithRemarks);

var classDoc = expAction.Context.Documentation.GetDocumentationMember(type);
Assert.NotNull(classDoc);
Assert.Equal("Class remark.", classDoc.Remarks.Text);

var memberDoc = expAction.Context.Documentation.GetDocumentationMember(type.GetProperty(nameof(SomeClassWithRemarks.ClassProp)));
Assert.NotNull(memberDoc);
Assert.Equal("Property remark.", memberDoc.Remarks.Text);

var methodeDoc = expAction.Context.Documentation.GetDocumentationMember(type.GetMethod(nameof(SomeClassWithRemarks.Method)));
Assert.NotNull(methodeDoc);
Assert.Equal("Method remark.", methodeDoc.Remarks.Text);

var ctorRemark = expAction.Context.Documentation.GetDocumentationMember(type.GetConstructor(Array.Empty<Type>()));
Assert.NotNull(ctorRemark);
Assert.Equal("Ctor remark.", ctorRemark.Remarks.Text);
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static bool HasSummary(this DocumentationMember dm)
return dm.Summary != null && !string.IsNullOrEmpty(dm.Summary.Text);
}

public static bool HasRemarks(this DocumentationMember dm)
{
return dm.Remarks != null && !string.IsNullOrEmpty(dm.Remarks.Text);
}

public static bool HasParameters(this DocumentationMember dm)
{
return dm.Parameters != null && dm.Parameters.Length > 0;
Expand Down
18 changes: 18 additions & 0 deletions Reinforced.Typings/Xmldoc/Model/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public string Name
[XmlElement(ElementName = "summary")]
public DocumentationSummary Summary { get; set; }

[XmlElement(ElementName = "remarks")]
public DocumentationRemarks Remarks { get; set; }

[XmlElement(ElementName = "inheritdoc")]
public DocumentationInheritDoc InheritDoc { get; set; }

Expand Down Expand Up @@ -92,6 +95,21 @@ public override void ReadXml(XmlReader reader)
}
}

public class DocumentationRemarks : XmlIgnoreInner
{
public string Text { get; set; }

public override string ToString()
{
return Text;
}

public override void ReadXml(XmlReader reader)
{
Text = reader.ReadInnerXml().Trim();
}
}

public class DocumentationInheritDoc : XmlIgnoreInner
{
/// <summary>
Expand Down

0 comments on commit e730d68

Please sign in to comment.