Skip to content

Add source-generator support for byte property round-trip in typed mappers - #138

Merged
mrdevrobot merged 3 commits into
mainfrom
copilot/fix-byte-type-support
Aug 27, 2026
Merged

Add source-generator support for byte property round-trip in typed mappers#138
mrdevrobot merged 3 commits into
mainfrom
copilot/fix-byte-type-support

Conversation

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

byte properties in typed DocumentDbContext models were not being mapped by the source-generated serializer/deserializer, so persisted values (e.g. SlaveAddress = 8) were read back as default 0. This change adds explicit byte mapping in generated mappers and covers nullable/non-nullable byte round-trip behavior.

  • Mapper generation: primitive type support

    • CodeGenerator.GetPrimitiveWriteMethod now maps byte to WriteInt32.
    • CodeGenerator.GetPrimitiveReadMethod now maps byte to ReadInt32Coerced.
    • CodeGenerator.IsValueType now recognizes byte for nullable unwrapping paths.
  • Mapper generation: deserialization correctness

    • Generated read path now casts coerced numeric reads back to byte ((byte)), aligning stored BSON numeric values with CLR byte properties.
    • Byte type checks were tightened to exact byte matches to avoid accidental overlap with unrelated numeric type names.
  • Regression coverage

    • Added a dedicated typed entity with byte and byte? fields and corresponding context registration.
    • Added focused round-trip tests for:
      • non-null byte + non-null byte?
      • non-null byte + null byte?
public class ByteEntity
{
    public ObjectId Id { get; set; }
    public byte Value { get; set; }
    public byte? OptionalValue { get; set; }
}

Copilot AI linked an issue Aug 27, 2026 that may be closed by this pull request
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 byte property round-trip in typed mappers Aug 27, 2026
Copilot AI requested a review from mrdevrobot August 27, 2026 08:22
@mrdevrobot
mrdevrobot marked this pull request as ready for review August 27, 2026 08:43
Copilot AI lite review requested due to automatic review settings August 27, 2026 08:43
@mrdevrobot
mrdevrobot merged commit 69a8287 into main Aug 27, 2026
5 checks passed
@mrdevrobot
mrdevrobot deleted the copilot/fix-byte-type-support branch August 27, 2026 08:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 byte support 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 byte and byte? round-trips (including null).

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;

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.

byte Type not support

3 participants