Skip to content

Commit 0ff4332

Browse files
authored
Housekeeping Add use of dependent source generator to the Readme (#318) (#325)
1 parent c9074e5 commit 0ff4332

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ public partial class MyReactiveClass : ReactiveObject
200200
}
201201
```
202202

203+
### Usage Reactive property with other source generators
204+
205+
Roslyn source generators don’t have a defined run order and each generator sees the same initial compilation.
206+
Code/attributes that one generator emits aren’t visible to other generators in the same compilation round,
207+
so adding `[JsonPropertyName]`/`[JsonInclude]` from `ReactiveUI.SourceGenerators` won’t cause the `System.Text.Json`
208+
source generator to pick them up in that project. That’s by design of the generator pipeline (no inter-generator dependencies / ordering).
209+
210+
So `System.Text.Json` needs special care. In the case that you want to Json-serialize `[Reactive]`
211+
properties, and you want to use the `System.Text.Json` source generator they must run in different
212+
assemblies. The same applies to other source generators depending on the output of `ReactiveUI.SourceGenerators`.
213+
214+
Define types with `[Reactive]` properties in assembly `A`, and then define the
215+
`System.Text.Json.JsonSerializerContext` source generation context in assembly `B`, and let
216+
`B` reference `A`.
217+
203218
## Usage ObservableAsPropertyHelper `[ObservableAsProperty]`
204219

205220
ObservableAsPropertyHelper is used to create a read-only property from an IObservable. The generated code will create a backing field and a property that returns the value of the backing field. The backing field is initialized with the value of the IObservable when the class is instantiated.

0 commit comments

Comments
 (0)