Add a way to inherit documentation <inheritdoc /> #8984
Replies: 77 comments
-
Should Also, FWIW, I have an open pull request at dotnet/roslyn#15494 that addresses namespace documentation comments as described in dotnet/roslyn#15474 (which hasn't been closed or migrated yet). |
Beta Was this translation helpful? Give feedback.
-
@daveaglick Yes, having separate issues would be great. If you create a new one for one of these and link to it here, I'll edit the OP here. |
Beta Was this translation helpful? Give feedback.
-
@gafter 👍 I created #315 which is just a copy of dotnet/roslyn#15474 (so I guess that corresponding Roslyn issue can also be closed now) |
Beta Was this translation helpful? Give feedback.
-
Is's worth mentioning that this tag can be (and already is) supported by documentation generators. By making it a Roslyn feature it makes it first class by making IntelliSense work (e.g. hovering over calls in the class overriding the member shows the documentation). Also, it should be implied to reduce boilerplate without causing a compiler warning for missing documentation. |
Beta Was this translation helpful? Give feedback.
-
I believe a good way to start here would be examining the features currently provided by SHFB for this documentation element, and then identifying ones which would be impractical from an implementation perspective or "not particularly needed" from an overall usage perspective. 🔗 inheritdoc (Sandcastle XML Comments Guide) SyntaxI believe it's reasonable to use the same form as defined by SHFB: <inheritdoc [cref="member"] [select="xpath-filter-expr"] /> This element may be placed either as a top-level element or as an inline element in a documentation comment. CompilationThe compiler is updated in the following ways to account for this element:
Candidate for inheritance
Impacted warningsThe following warnings, which are specific to the Roslyn implementation of a compiler for C#, should be updated to account for this feature: CS1573
Care should be taken to not report this warning in the following scenario. It would be sufficient to disable this warning any time class Base {
/// <param name="x">Doc for x</param>
protected void Method1(int x) { }
}
class Derived : Base {
/// <inheritdoc cref="Base.Method1"/>
/// <param name="y">Doc for y</param>
protected void Method2(int x, int y) { }
} CS1712
This is similar to the previous case, but applies for type parameters. The example shows type parameters for a generic type, but it can also apply to generic methods. /// <typeparam name="T">Doc for T</param>
class Base<T> {
}
/// <inheritdoc/>
/// <typeparam name="T2">Doc for T2</param>
class Derived<T, T2> : Base<T> {
} ToolsThis section describes the manner (semantics) in which Will be added in a later comment |
Beta Was this translation helpful? Give feedback.
-
Why shouldn't |
Beta Was this translation helpful? Give feedback.
-
I agree with @pascalberger above about replacing in the XML documentation file. There are tools, including documentation generators, that use the XML doc file as a substitute for having access to the source. If the If that's not feasible, perhaps the |
Beta Was this translation helpful? Give feedback.
-
Ignoring the "it's what we do now" issue, three immediate reasons:
I would expect Roslyn to provide an API which provides code element documentation with |
Beta Was this translation helpful? Give feedback.
-
While I see the advantages you mention, another downside, beside documentation generators mentioned by @daveaglick, of this approach is that if a library is created with |
Beta Was this translation helpful? Give feedback.
-
That's a very good point. I forgot I use SHFB as a preprocessor to resolve these before packaging NuGet from projects that use inheritdoc. |
Beta Was this translation helpful? Give feedback.
-
Given the potential pitfalls, I'm very much against adopting the |
Beta Was this translation helpful? Give feedback.
-
Do you have examples? I've only very rarely needed |
Beta Was this translation helpful? Give feedback.
-
@sharwell you could, for instance, select the second paragraph via |
Beta Was this translation helpful? Give feedback.
-
I'll also ++ for no |
Beta Was this translation helpful? Give feedback.
-
@matkoch I've never seen someone do that. Considering that it's hard to get users to write any documentation, much less put thought into the specific content resulting from what they write, I do not anticipate any notable number of problems arising from this feature. The only thing I've ever used it for IIRC was to remove a "note to implementers" that would otherwise have been inherited. It was a strange message to otherwise be included in the documentation for a sealed method, and I was happy to have a way to remove it. |
Beta Was this translation helpful? Give feedback.
-
@albert-github The |
Beta Was this translation helpful? Give feedback.
-
@sharwell This shines a bit of new light on the problem.
|
Beta Was this translation helpful? Give feedback.
-
The correct place to expand the documentation would probably be the XML documentation chapter on this, i.e. the following document on GitHub: https://github.com/dotnet/docs/blob/master/docs/csharp/programming-guide/xmldoc/inheritdoc.md. |
Beta Was this translation helpful? Give feedback.
-
@poke Looks like promising, though I don't see any reference that this is a repository intended for preparing for standardization by e.g. ECMA / ISO / ... |
Beta Was this translation helpful? Give feedback.
-
This repository is about additions to the C# language. Eventually, such changes will make their way into the ecma spec, as they are part of the language. |
Beta Was this translation helpful? Give feedback.
-
@333fred Nearly contradicting to previous comments, but as I understand it now the |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is the right place; Sorry if it's not. I've noticed that Eg.: /// <summary>a</summary>
public void A() {}
/// <inheritdoc cref="A()"/>
/// <summary>b</summary>
/// <returns>foo</returns>
public void B() {} The output docs for
When I expected:
|
Beta Was this translation helpful? Give feedback.
-
tagging @sharwell . however, it's not a case where one set of docs is brought in, then overwritten by other docs. Rather, the set of docs brought in is just brought in verbatim with no processing done on it. |
Beta Was this translation helpful? Give feedback.
-
Is it intended that For example, a constructor might take values to populate the class properties, and the parameters of that constructor will have the same description as the original property. For example: class MyEntity
{
/// <summary>
/// The code of the item
/// </summary>
public string Code
{
get;
set;
}
/// <summary>
/// The description of the item
/// </summary>
public string Description
{
get;
set;
}
/// <summary>
/// Creates a new entity
/// </summary>
/// <param name="code"><inheritdoc cref="MyEntity.Code"/>/param>
/// <param name="description"><inheritdoc cref="MyEntity.Description"/>/param>
public MyEntity(string code, string description)
{
}
} Currently this example inserts blank values in place of the |
Beta Was this translation helpful? Give feedback.
-
It was intended that In your case you are using Personally, I don't like how it functions based on x-paths by default, but it was intended. |
Beta Was this translation helpful? Give feedback.
-
sorry I bumped the comment button earlier than intended... Here is an example that will fix your issue @geoffbon class MyEntity
{
/// <summary>
/// The code of the item
/// </summary>
public string Code
{
get;
set;
}
/// <summary>
/// The description of the item
/// </summary>
public string Description
{
get;
set;
}
/// <summary>
/// Creates a new entity
/// </summary>
/// <param name="code"><inheritdoc cref="Code" path="/summary"/></param>
/// <param name="description"><inheritdoc cref="Description" path="/summary"/></param>
public MyEntity(string code, string description)
{
}
} If you explicitly provide an x-path (via the |
Beta Was this translation helpful? Give feedback.
-
This is outstanding, thanks so much @ZacharyPatten! This makes a lot more sense to me now. |
Beta Was this translation helpful? Give feedback.
-
vs 17.4 has added the inherit doc feature, but what is the shortcut? |
Beta Was this translation helpful? Give feedback.
-
@Varorbc what sort of shortcut are you looking for? If you want IntelliSense to inherit the full documentation for an interface member or abstract method, it already does that if you simply omit the documentation comment entirely. |
Beta Was this translation helpful? Give feedback.
-
Champion issue: #8985
(moved from part of dotnet/roslyn#67 by @dfkeenan, with part of the request tracked at #315)
Hi,
Please add
<inheritdoc />
tag or similar:I think it would be really handy if the compiler(s) when outputting the documentation XML file if it could use inherited documentation where available/requested. Though I am not sure what should be output if there is no documentation available.
P.S. A Diagnostic and Code Fix that generates document comments for me would also great 😃
Beta Was this translation helpful? Give feedback.
All reactions