Skip to content

fix: generate bindings in views that [IViewFor] makes implement IViewFor<T> - #558

Merged
glennawatson merged 1 commit into
mainfrom
fix/bind-iviewfor-attribute-views
Nov 27, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/bind-iviewfor-attribute-views

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

Bindings in a view marked [IViewFor<T>] or [IViewFor("Name")] now get generated code, so they no longer need the Unsafe overloads or raise RXUIBIND021.

  • The binding generator reads both forms of [IViewFor] and sees the IViewFor<T> interface and the ViewModel, BindingRoot and IViewFor.ViewModel properties that ReactiveUI.SourceGenerators adds to the view.
  • It follows that generator's rules: only a partial class that derives from a WPF, Windows Forms, WinUI, MAUI, Avalonia or Uno control gains them, and a Windows Forms view gains no BindingRoot.
  • A view marked both [IReactiveObject] and [IViewFor] keeps both interfaces.

Why

No generator sees another generator's output. The binding generator already declares the members [Reactive], [BindableDerivedList] and the other attributes write, so call sites that bind them can be read. It did not do this for [IViewFor], so in a view that gets IViewFor<T> from the attribute, this.OneWayBind(ViewModel, ...) had no ViewModel and no interface to bind against. Nothing was generated, RXUIBIND021 was reported, and the call needed OneWayBindUnsafe. A view that derives from ReactiveUserControl<T> was not affected, which is why the problem appeared after switching to [IViewFor<T>].

Closes #557

Breaking changes

None

How this was verified

The contract tests run ReactiveUI.SourceGenerators' real IViewForGenerator beside the binding generator. They bind a [BindableDerivedList] list and a [Reactive] property from views marked with each form of [IViewFor], then run the bindings in both runtime flavours, with and without interceptors. With the new declarations removed, those bindings throw the "No generated OneWayBind dispatch" error from the issue. The declaration tests cover each rule above. The Linux examples suite passes, including the native AOT publish of setup/aot.

Notes for the reviewer

Start with SourceGeneratorsMemberExtractor.ExtractIViewFor. It reuses the view locator's ResolveViewModel and ReferencedViewNamespace, so the view model and the runtime flavour are found the same way the view locator finds them. In SourceGeneratorsCompilation.Add, a member can now carry an interface and properties together, and a second interface on the same type is appended rather than replacing the first.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

…For<T>

- Read [IViewFor<T>] and [IViewFor("Name")] by metadata name, and declare the IViewFor<T> interface, ViewModel, BindingRoot and IViewFor.ViewModel they add.
- Follow that generator's rules: only partial classes deriving from a WPF, Windows Forms, WinUI, MAUI, Avalonia or Uno control, with no BindingRoot on a Windows Forms view.
- Keep both interfaces on a type marked [IReactiveObject] and [IViewFor].
- Run the real IViewForGenerator beside the binding generator in the contract tests.
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.09%. Comparing base (5c874f9) to head (ec692ff).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #558   +/-   ##
=======================================
  Coverage   99.09%   99.09%           
=======================================
  Files         487      487           
  Lines       19240    19275   +35     
  Branches     2893     2903   +10     
=======================================
+ Hits        19065    19100   +35     
  Misses        175      175           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit d1b9ab5 into main Nov 27, 2026
26 checks passed
@glennawatson
glennawatson deleted the fix/bind-iviewfor-attribute-views branch November 27, 2026 22:36
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.

OneWayBind() of [BindableDerivedList] when using [IViewFor<T>]

1 participant