Skip to content

Feature/bitfield change detector factory#1

Closed
matt05d wants to merge 3 commits intomainfrom
feature/bitfield-change-detector-factory
Closed

Feature/bitfield change detector factory#1
matt05d wants to merge 3 commits intomainfrom
feature/bitfield-change-detector-factory

Conversation

@matt05d
Copy link
Collaborator

@matt05d matt05d commented Mar 25, 2026

This adds an optional codegen feature to automatically create a BitfieldChangeDetector setup based on the schema.

New Schema.GenerateChangeDetectionFactory flag (opt-in).
Finds bitfields with level mappings.
Emits a {SchemaName}ChangeDetection static class.
Adds a CreateDetector() method that returns a preconfigured detector.

What it generates:

public static BitfieldChangeDetector<Client> CreateDetector() { return new BitfieldChangeDetector<Client>() .Track(c => c.SomeBitfield, v => v.GetLevel()) .Track(c => c.AnotherBitfield, v => v.GetLevel()); }

Why?

This saves time in the consuming projects as individual register tracking is no longer required if you enable the factory.
Consumer requirements:

You’ll need to provide a BitfieldChangeDetector with:

BitfieldChangeDetector<TClient> Track<T>( Func<TClient, T> getter, Func<T, Level> getLevel) where T : struct, Enum;

For each schema with bitfield points that have level annotations, emit
a static factory method that returns a BitfieldChangeDetector configured
with the appropriate property getters and GetLevel calls. The runtime
change detection logic lives in the consuming project.
The source generator now emits a change detection factory that
references BitfieldChangeDetector<T>, which lives in the consuming
project. The test project needs a minimal stub so the generated
code compiles.
@matt05d matt05d closed this Mar 25, 2026
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.

2 participants