SHFB icon indicating copy to clipboard operation
SHFB copied to clipboard

Question about <inheritdoc /> tag

Open Nicolas4tin opened this issue 10 years ago • 6 comments

Hello everyone,

With <inheritdoc /> tag is it possible to inherit in <remarks> a part of the comments that is in <summary>? What I mean is described in the example below, but it doesn't do what I want:

namespace Person
{
    /// <summary>
    /// This class represents <span id="Desc">a boy name, age and his wallet</span>.
    /// </summary>
    /// <remarks>
    /// The class is <inheritdoc select="span[@id='Desc']" />
    /// </remarks>
    public class Boy
    {
    }
}

I also try that to no avail, since Sandcastle doesn't allow circular reference:

    /// The class is <inheritdoc cref="T:Person.Boy" select="span[@id='Desc']" />

This way is allowed, but it doesn't do what I expect:

    /// The class is <inheritdoc cref="T:PersonProject.Person.Boy" select="span[@id='Desc']" />

Best regards,

Nicolas

Nicolas4tin avatar Aug 19 '16 15:08 Nicolas4tin

In the absence of a cref attribute, the inherited documentation will only come from the base types' comments for the given member within the like-named comment element. In your example, since Boy has no base class, it wouldn't find anything to inherit from.

If a cref attribute is specified, it will pull the comments from there. If you just specify Boy, the compiler should fully qualify the class name when it creates the XML comments file. If you include the T: prefix you do need to fully qualify the name with the namespaces. So, in this case T:Person.Boy should work.

Where you're probably running into problems is that the select attribute's XPath query isn't rooted so it's going to try and pull the comments from the remarks element of the cref target which, in this case, is itself hence the circular reference. If you want to pull from the summary element, you need to make it a rooted XPath query and tell it which element to get the span from. This should work:

/// Select from <inheritdoc cref="Boy" select"/summary/span[@id='Desc']" />
/// Or
/// Select from <inheritdoc cref="T:Person.Boy" select"/summary/span[@id='Desc']" />

EWSoftware avatar Aug 19 '16 19:08 EWSoftware

Hello Eric,

Thanks for answering.

I tried both <inheritdoc /> that you told me:

/// The class is <inheritdoc cref="T:Person.Boy" select="/summary/span[@id='Desc']" />
/// or
/// The class is <inheritdoc cref="Boy" select="/summary/span[@id='Desc']" />

There is still circular reference in both case:

SHFB: Error GID0001: Unexpected error while generating inherited documentation:
SandcastleBuilder.Utils.InheritedDocumentation.InheritedDocsException: Circular reference detected.
Documentation inheritance stack:
    2: T:Person.Boy
    1: T:Person.Boy

   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.InheritDocumentation(XmlNode member)
   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.LocateBaseDocumentation(String name, String cref)
   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.InheritNestedDocumentation(XmlNode member)
   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.InheritDocumentation(XmlNode member)
   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.ScanCommentsFiles()
   … SandcastleBuilder.InheritedDocumentation.GenerateInheritedDocs.Main(String[] args)
    Last step completed in 00:00:00,2617
-------------------------------

SHFB: Error BE0043: Unexpected error detected in last build step.  See build log for details.
   à SandcastleBuilder.Utils.BuildEngine.TaskRunner.Run(String processFilename, String targetFile, String arguments)
   à SandcastleBuilder.Utils.BuildEngine.BuildProcess.Build()

Do you have another idea?

Best regards,

Nicolas

Nicolas4tin avatar Aug 19 '16 19:08 Nicolas4tin

I see the problem. Inherited documentation itself may contain inheritdoc elements that have not yet been processed. So, as part of obtaining the documentation to inherit it has to process any inheritdoc tags it finds in the member to inherit from.

What I could do is demote the circular reference error to a warning and just return the comments as they are. That would allow the above scenario to work with the downside being that if you did it a lot, you'd see lots of "circular reference" warnings in the build log.

EWSoftware avatar Aug 19 '16 21:08 EWSoftware

Hello Eric,

Thank you for your answer. For me it's not a bing concern, if there is more warnings when <inheritdoc /> inherits documentation at the same place where the tag is (class, method, property, etc.). I don't use this pattenrn a lot. I guess that it might be the same for others people. So it would be a nice feature to have for me. If you agree to demote the circular reference, I would be glad. If not, I would have to copy my documentation. Although it's not the best option, I have a workaround. So it's up to you to decide.

Thank you and have a nice day.

Nicolas

Nicolas4tin avatar Aug 22 '16 13:08 Nicolas4tin

It's no problem so I'll get it in the next release.

EWSoftware avatar Aug 22 '16 15:08 EWSoftware

Hello Eric,

Thanks a lot. You can close the thread if you want or keep it opens as a reminder.

Best regards,

Nicolas

Nicolas4tin avatar Aug 22 '16 15:08 Nicolas4tin