Add source-generator support for byte property round-trip in typed mappers - #138
Merged
Conversation
Closed
Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix byte type not supported in database saving
Add source-generator support for Aug 27, 2026
byte property round-trip in typed mappers
mrdevrobot
approved these changes
Aug 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a typed-mapper source generation gap where byte / byte? properties were not correctly round-tripped through the generated BSON serializer/deserializer, causing persisted byte values to be read back as 0.
Changes:
- Added
bytesupport to the source generator’s primitive read/write method selection and value-type detection. - Updated generated read-path emission to cast coerced numeric reads back to
byte. - Added regression tests and a test entity/context registration to validate
byteandbyte?round-trips (includingnull).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/BLite.Tests/BytePropertyTests.cs | Adds regression tests for byte and byte? round-trip behavior. |
| tests/BLite.Shared/TestDbContext.cs | Registers ByteEntity collection and model mapping for typed-context tests. |
| tests/BLite.Shared/MockEntities.cs | Introduces ByteEntity used by the new tests. |
| src/BLite.SourceGenerators/CodeGenerator.cs | Extends primitive mapping logic and generated read code to support byte round-trips. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1
to
+5
| using BLite.Shared; | ||
| using System; | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
|
|
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.
byteproperties in typedDocumentDbContextmodels were not being mapped by the source-generated serializer/deserializer, so persisted values (e.g.SlaveAddress = 8) were read back as default0. This change adds explicitbytemapping in generated mappers and covers nullable/non-nullable byte round-trip behavior.Mapper generation: primitive type support
CodeGenerator.GetPrimitiveWriteMethodnow mapsbytetoWriteInt32.CodeGenerator.GetPrimitiveReadMethodnow mapsbytetoReadInt32Coerced.CodeGenerator.IsValueTypenow recognizesbytefor nullable unwrapping paths.Mapper generation: deserialization correctness
byte((byte)), aligning stored BSON numeric values with CLRbyteproperties.bytematches to avoid accidental overlap with unrelated numeric type names.Regression coverage
byteandbyte?fields and corresponding context registration.byte+ non-nullbyte?byte+ nullbyte?