-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to reference a method group in XML comment #320
Comments
@EWSoftware What does SHFB do in a situation where all of the following occur:
In this situation, no overloads page would be generated for the method group, and I would expect the rendered reference to point directly to the public method, which is the only one included in the final documentation. Do you foresee any problems with SHFB handling |
As currently written, an overload link will only link to an overload page. If the overload target ID doesn't exist in the reflection data, it will generate a non-link and issue an "unknown reference link" warning. That would be the case above if private methods are excluded. If private methods are included or both are public, the normal overload page would be generated and it would work as expected. That should be easy enough to change so that it works either way. All it should need to do is when the target isn't found and the ID starts with "Overload:", change it to "M:" and see if there's a key that starts with that ID. If so, use it, otherwise, treat it as an unknown reference link as before. As currently written, the presentation style transforms convert the "O:" to "Overload:" to match the topic ID generated by the document model transformation hence the full word above. I think it was probably spelled out to make it clear it wasn't a standard prefix and to avoid any possible conflict. It can look for either prefix in case that were to ever change in future presentation styles. |
@EWSoftware Thank you for the awesome details. I was a bit concerned originally regarding a change like my proposal breaking documentation rendering tools (or forcing us to treat method visibility in a manner unique to this feature), but it sounds like that the problems would actually be minor and resolvable. @gafter If I was interested in formalizing this proposal as a modification to the language specification, what would be a good way to proceed? |
@sharwell If the goal is to "get it done", I think the first step is to write up a semi-formal description of what exactly you want to change, and how, with plenty of motivational discussion. A working prototype would help, but it isn't absolutely required. Then the second step is to find someone on the @dotnet/csharplangdesign (LDM) team who would be willing to act as an advocate for the proposal (i.e. advocate prioritizing it over other things we could do) to the LDM. Once a champion is identified, he would create a champion issue, and the LDM will triage it. |
@gafter Aside from the fact that I would find this feature useful myself, I asked due to my interest in the following:
|
@sharwell I've updated the By the way, here's something I'd forgotten. If you specify |
This would be a useful feature, in my experience. Adding an overload can break docs, but more often it just allows more succinct documentation when you can refer to a group of overloads rather than having to list them all out explicitly (further exposing yourself to breaks following changes). |
Nice one |
These are experimental features. We shall allow callers to decide whether to turn them on or off until we can refactor the implmenetations out to form decoupled classses.
This request seems stale but needs to be resolved. To be honest there is no way to fix this compiler warning "properly" without using a suppression pragma right now. Any other approach causes other problems.
Additionally, and it may just be a setting I have with an analyzer or something, crefs marked with a prefix generate a warning about avoiding the use of prefixes. I don't see this problem right now in the codebase I'm working on but it is the reason we switched to the pragma instead of using the prefix. So at this point the only solution that works for me that doesn't break refactoring is using a pragma to disable the warning. Would love to see this fixed soon. |
@DustinCampbell any chance this could move forward? In the .NET Libraries team, we want the triple slash comments in source code to be considered the source of truth for documentation. Currently, the source of truth for us is MS Docs (full proposal). I am working on this tool that backports MS Docs descriptions into source code xml comments. MS Docs supports expressing method overloads in see crefs by appending My backporting tool detects these strings and removes Unfortunately, this is causing a build error (since we turn on the mandatory triple slash comments for public APIs). I have two workarounds:
|
mark. You guys are great! |
tl;dr
This is a proposal to extend the syntax supported by XML documentation comments to allow documentation comments to reference a group of overloaded methods, and allow these references to be verified at compile time.
Summary
Currently the following works. It compiles without warning and the documentation comment contains a reference to the
Foo()
method.However, the following does not work:
The specific warning produced is:
To reference a method group, the following syntax is required:
This is problematic for the following reasons:
I propose the following modification to the way parameterless method references are resolved:
O:
form listed above.Details
Processing of documentation comments during the compilation process behaves as a source-to-source transformation. The C# Language Specification is not clear with respect to the syntax and/or limitations of referencing code elements from a
cref
attribute. However, the structure of the compiled output is more clear.Changes to input form
There are no changes to the lexical structure of the input or to symbol resolution when building the semantic model. When generating documentation comment IDs for the purpose of writing resolved references to the output, a new special case is provided for references which do not specify parameters or type parameters. In this case, when the reference resolves to more than one candidate symbol, all of which are methods, the compiler will no longer report CS0419.
Open questions:
Changes to output form
The ID string format defined in the language specification is amended to include the following member kind:
In addition, the description of the format for methods and properties is modified to read as follows:
📝 Originally copied from dotnet/roslyn#45, then modified to formalize the proposal.
The text was updated successfully, but these errors were encountered: