Add PolyType support for efficient serialization integration#1
Draft
Add PolyType support for efficient serialization integration#1
Conversation
- Add TypeShapeAttribute detection to VogenKnownSymbols - Add utility methods for generating PolyType attribute and marshaler - Integrate PolyType generation into all four generators (Class, Struct, RecordClass, RecordStruct) - PolyType code only generated when PolyType.TypeShapeAttribute is available in compilation Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
- Add snapshot tests for PolyType functionality - Create validation script demonstrating expected behavior - Tests verify conditional generation based on PolyType availability Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Author a pull request that resolves @SteveDunn/Vogen/issues/834
As described in the issue, only emit the additional code in the source generator for compilations that include
Add PolyType support for efficient serialization integration
Aug 27, 2025
PolyType.TypeShapeAttribute as a metadata type in the compilation.Removed unnecessary whitespace and comments in PolyTypeTests.cs
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 implements support for PolyType integration as requested in issue SteveDunn#834. The implementation conditionally emits additional code when
PolyType.TypeShapeAttributeis available in the compilation, enabling seamless integration between Vogen value objects and PolyType-based serialization libraries like Nerdbank.MessagePack.Problem Statement
PolyType is a high-performance type modeling library that uses source generation to expose type graphs at runtime. However, PolyType's source generator cannot see code emitted by Vogen's source generator, creating a compatibility issue. This forces users to either:
Solution
When
PolyType.TypeShapeAttributeis detected in the compilation, Vogen now automatically generates:IMarshaler<T, TUnderlying>This enables PolyType to efficiently serialize/deserialize the underlying primitive value directly, bypassing the wrapper type and producing optimal schemas.
Example
For a value object like:
When PolyType is available, Vogen now generates:
Implementation Details
PolyType.TypeShapeAttributeis found in the compilationglobal::prefixes and follows existing Vogen patternsBenefits
This resolves the core incompatibility between PolyType and Vogen source generators, enabling developers to use both libraries together seamlessly for efficient, type-safe serialization.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.