Skip to content

Epic: Add new SetBinding API for defining "compiled" bindings in code #22384

@simonrozsival

Description

@simonrozsival

We agreed to implement a new public API to allow creating "compiled" bindings (TypedBinding<TSource, TProperty>) in code via source-generators and interceptors based on the proposal #20574 (see Alternative design).

  • Introduce new public method BindableObjectExtensions.SetBinding<TSource, TProperty>(BindableProperty property, Func<TSource, TProperty> getter, ...) as defined in the proposal
  • Create a new source generator
    • Intercept calls to SetBinding<TSource, TProperty>(...)
    • Parse getter lambda expression
      • Implement support for properties
      • Implement support for indexers
      • Implement support for as-casts
      • Implement support for C-style casts
      • Implement support for conditional access to members
      • Implement diagnostics reporting
      • Build cacheable data model
    • Generate setter from the getter lambda
    • Generate handlers array from the getter lambda
  • Enable the source generator by default in MAUI apps
    • Introduce a feature switch to disable the source generator
  • Add unit tests for correct caching of the generated code
  • Run benchmarks comparing reflection-based binding, source-generated binding, and hand-written typed binding
  • Write docs/developer guide - tracked in .NET MAUI 9: Compiled bindings can be used with C# markup docs-maui#2304

Possible future improvements

Metadata

Metadata

Labels

EpicGroups multiple user stories. Can be grouped under a theme.area-xamlXAML, CSS, Triggers, Behaviors

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions