Serializer for shorter YAML tags when using abstract base types#6407
Open
Ataman wants to merge 2 commits intospace-wizards:masterfrom
Open
Serializer for shorter YAML tags when using abstract base types#6407Ataman wants to merge 2 commits intospace-wizards:masterfrom
Ataman wants to merge 2 commits intospace-wizards:masterfrom
Conversation
Contributor
Author
|
PR #6227 appears to use RA0045 already. Will check and update before merge if it comes to that. |
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.
This PR adds a custom serializer named
CustomBaseTypeSerializerthat lets coders shorten the whole!type:BaseTypeSomethinginto just!Somethinggiven that the base type ends inBaseand their concrete implementations replaceBase(and onlyBase) withSomething. The serializer only applies when specified using theDataFieldattribute and includes support for most common collections.Includes a DiagnosticAnalyzer with pre-compile time check (to prevent the serializer being applied on incorrectly named types) and unit tests for serializer and analyzer. It adds RA0045 to Diagnostics.cs for the analyzer. I couldn't find any conventions or process for requesting these and just added it for now, correct me if I got it wrong.
Rider comparison of hypothetical YAML before and after applying the serializer:

Finally, I'm not that proficient with YAML, feel free to reject this and suggest a better solution (or a better name instead of
CustomBaseTypeSerializer). I'm happy to write something different if it's useful. This was also my first time writing a DiagnosticAnalyzer; it looks fortypeof()expressions and checks the type param whenCustomBaseTypeSerializeris in use. If there is a better approach, let me now.