-
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
cref instantiated types proposal #1751
Open
sharwell
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
sharwell:cref-instantiated-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# `cref` instantiated types | ||
|
||
* [x] Proposed | ||
* [ ] Prototype: [Complete](https://github.com/PROTOTYPE_OWNER/roslyn/BRANCH_NAME) | ||
* [ ] Implementation: [In Progress](https://github.com/dotnet/roslyn/BRANCH_NAME) | ||
* [ ] Specification: [Not Started](pr/1) | ||
|
||
## Summary | ||
[summary]: #summary | ||
|
||
<!-- One paragraph explanation of the feature. --> | ||
|
||
This feature allows users to reference closed generic types in `cref` attributes of documentation comments. | ||
|
||
## Motivation | ||
[motivation]: #motivation | ||
|
||
<!-- Why are we doing this? What use cases does it support? What is the expected outcome? --> | ||
|
||
Currently documentation comments cannot reference instantiated generic types. This is especially problematic for cases such as asynchronous programming, where documentation for return values cannot easily express both the task-like return type (e.g. `Task<TResult>`) and the type of value held by the task (e.g. `int` for `ValueTask<int>`). | ||
|
||
## Detailed design | ||
[design]: #detailed-design | ||
|
||
<!-- This is the bulk of the proposal. Explain the design in enough detail for somebody familiar with the language to understand, and for somebody familiar with the compiler to implement, and include examples of how the feature is used. This section can start out light before the prototyping phase but should get into specifics and corner-cases as the feature is iteratively designed and implemented. --> | ||
|
||
`cref` attributes are updated to allow generic type references to provide type arguments: | ||
|
||
```xml | ||
<see cref="Dictionary{int, string}"/> | ||
``` | ||
|
||
The documentation comment ID for instantiated generic types is given the following form: | ||
|
||
``` | ||
T:System.Collections.Generic.Dictionary`2[[System.Int32, System.String]] | ||
``` | ||
|
||
Post-processing tools for documentation comments SHOULD use the type instantiation when rendering the documentation. | ||
|
||
> [Dictionary](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<[int](https://docs.microsoft.com/en-us/dotnet/api/system.int32), [string](https://docs.microsoft.com/en-us/dotnet/api/system.string)> | ||
|
||
Post-processing tools MAY ignore the type instantiation provided in double-brackets, and render the reference in a form like the following: | ||
|
||
> [Dictionary<TKey, TValue>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2) | ||
|
||
## Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
<!-- Why should we *not* do this? --> | ||
|
||
The current C# compiler ignores the specific identifiers passed in references to generic types. In many cases, the new behavior more closely matches the behavior users expect, but it still produces a change in the output files. In some cases, new warnings would be reported. | ||
|
||
## Alternatives | ||
[alternatives]: #alternatives | ||
|
||
<!-- What other designs have been considered? What is the impact of not doing this? --> | ||
|
||
## Unresolved questions | ||
[unresolved]: #unresolved-questions | ||
|
||
<!-- What parts of the design are still undecided? --> | ||
|
||
* How should the open generic type be referenced if a name matching the type parameter appears in the scope of the reference? | ||
* One option is to allow `<see cref="Dictionary{,}"/>` | ||
|
||
## Design meetings | ||
|
||
<!-- Link to design notes that affect this proposal, and describe in one sentence for each what changes they led to. --> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this also be supported partially, e.g.
<see cref="Dictionary{int,}"/>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Joe4evr That seems complex for consumers of the XML. Why would you want to represent that? It's not even representable in C#.