Skip to content

Serializer for shorter YAML tags when using abstract base types#6407

Open
Ataman wants to merge 2 commits intospace-wizards:masterfrom
Ataman:custom-base-type-serializer
Open

Serializer for shorter YAML tags when using abstract base types#6407
Ataman wants to merge 2 commits intospace-wizards:masterfrom
Ataman:custom-base-type-serializer

Conversation

@Ataman
Copy link
Contributor

@Ataman Ataman commented Feb 2, 2026

This PR adds a custom serializer named CustomBaseTypeSerializer that lets coders shorten the whole !type:BaseTypeSomething into just !Something given that the base type ends in Base and their concrete implementations replace Base (and only Base) with Something. The serializer only applies when specified using the DataField attribute 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:
image

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 for typeof() expressions and checks the type param when CustomBaseTypeSerializer is in use. If there is a better approach, let me now.

@Ataman
Copy link
Contributor Author

Ataman commented Feb 3, 2026

PR #6227 appears to use RA0045 already. Will check and update before merge if it comes to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant