-
-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Describe the bug 🐞
When creating a partial property with ObservableAsProperty attribute in a class which is subclass of ReactiveObject the generated code is different from the code that gets generated when applying the ObservableAsProperty to a field.
Applying the ObservableAsProperty to a field will generate code that gives you a CS8618 warning in the classes custom constructors that the generated helper field must contain a non-null value when exiting constructor.
Applying the ObservableAsProperty to a partial property it will generate code that doesn't give you the CS8618 warning.
Step to reproduce
- Create a new .NET9 class library project (with Nullable enabled)
- Install the ReactiveUI and ReactiveUI.SourceGenerators packages
- Write a simple partial class which is a subclass of ReactiveObject
- Add a partial get-only property with [ObservableAsProperty] attribute and a field [ObservableAsProperty] attribute
- Add one or more constructors
public partial class TestClass : ReactiveObject
{
[ObservableAsProperty]
private bool _observableTestField;
public TestClass()
{
}
[ObservableAsProperty]
public partial bool ObservableTestProperty { get; }
}- See that a CS8618 warning is generated for the generated
_observableTestFieldHelperfield but not for the generated_observableTestPropertyHelperfield.
Reproduction repository
https://github.com/DarkCloud14/ReactiveUI_SourceGen_ObservableAsProperty_Issue
Expected behavior
I would expect that in both cases code is generated which would result in a CS8618 warning if the helper field doesn't contain a non-null value when exiting the constructor.
Screenshots 🖼️
No response
IDE
Rider macOS
Operating system
macOS Sequoia 15.3.1
Version
No response
Device
No response
ReactiveUI Version
ReactiveUI 20.1.63, ReactiveUI.SourceGenerators 2.1.1
Additional information ℹ️
No response