Update the DeclarePublicAPI analyzer to consider return types#359
Merged
tmeschter merged 1 commit intodotnet:masterfrom Feb 10, 2015
Merged
Conversation
The DeclarePublicAPI draws attention to changes to the public API surface area in order to prevent breaking changes and to encourage careful design when adding new APIs. It requires that every project with a public API capture the public types and members in a file called PublicAPI.txt, and creates errors when this file does not match the actual symbols in the project. This makes changes very obvious in code reviews and source control history. Currently PublicAPI.txt does not capture the return types of members (field, properties, methods, and events) so these can changes without it being caught by the tool. This changes updates the analyzer to include the return type. A nice feature of the associated code fix is that it sorts PublicAPI.txt alphabetically, and since type names are fully qualified this naturally groups together types in the same namespace, members in the same type, overloads, etc. To preserve this property we put the return type at the end of the line, after the type and member name.
Contributor
|
👍 |
Contributor
Author
|
FYI, the Jenkins build failed for unrelated reasons. |
Contributor
There was a problem hiding this comment.
Instead of this method, can you not simply update your SymbolDisplayFormat to set IncludeType ?
Contributor
Author
There was a problem hiding this comment.
I considered that, but then the call to symbol.ToDisplayString(PublicApiFormat) would put the return type at the beginning of the string. Since the code fix does a simple alphabetical sort of the lines in PublicAPI.txt, the symbols would then be sorted primarily by return type, rather than by type and member name.
Contributor
|
👍 |
tmeschter
added a commit
that referenced
this pull request
Feb 10, 2015
Update the DeclarePublicAPI analyzer to consider return types
dibarbet
pushed a commit
to dibarbet/roslyn
that referenced
this pull request
Nov 21, 2025
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #289.
The DeclarePublicAPI draws attention to changes to the public API
surface area in order to prevent breaking changes and to encourage
careful design when adding new APIs. It requires that every project with
a public API capture the public types and members in a file called
PublicAPI.txt, and creates errors when this file does not match the
actual symbols in the project. This makes changes very obvious in code
reviews and source control history.
Currently PublicAPI.txt does not capture the return types of members
(field, properties, methods, and events) so these can changes without it
being caught by the tool. This changes updates the analyzer to include
the return type.
A nice feature of the associated code fix is that it sorts PublicAPI.txt
alphabetically, and since type names are fully qualified this naturally
groups together types in the same namespace, members in the same type,
overloads, etc. To preserve this property we put the return type at the
end of the line, after the type and member name.