Describe the bug 🐞
It looks like the named parameter ReadOnly of the ObservableAsProperty attribute is ignored when you use it at a partial property.
When you explicitly set ReadOnly to true the generated OAPH field isn't readonly and the same is true if you don't supply the parameter at all, this then also generates an OAPH field which isn't readonly and so in this regard is behaving different to specifying OAP attribute at a field without ReadOnly parameter which results in a readonly OAPH field.
I discovered that issue when looking into another issue which I reported here
Step to reproduce
- Create a new .NET9 class library project
- 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 with [ObservableAsProperty] attribute
- Add another partial get-only property with
[ObservableAsProperty(ReadOnly = true)] attribute and a field with [ObservableAsProperty(ReadOnly = true)] attribute
public partial class TestClass : ReactiveObject
{
[ObservableAsProperty]
private string _observableTestFieldNotSet;
[ObservableAsProperty(ReadOnly = true)]
private string _observableTestFieldReadOnlyTrue;
[ObservableAsProperty]
public partial string ObservableTestPropertyNotSet { get; }
[ObservableAsProperty(ReadOnly = true)]
public partial string ObservableTestPropertyReadOnlyTrue { get; }
}
- Have a look at the generated source code and see that both helper fields of the partial properties
ObservableTestPropertyNotSet and ObservableTestPropertyReadOnlyTrue are not readonly. When looking at the helper fields generated for the fields _observableTestFieldNotSet and _observableTestFieldReadOnlyTrue this is the case meaning both are readonly.
Reproduction repository
https://github.com/DarkCloud14/ReactiveUI_SourceGen_ObservableAsProperty_ReadOnly_Issue
Expected behavior
I would expect that only if you explicitly set the named parameter ReadOnly of ObservableAsProperty attribute to false at a partial property the generated OAPH field isn't readonly and in the other two cases (not supplied at all or explicitly set to true) it is readonly.
The reason I would expect the above behaviour is because that's the result if you do that at a field instead of a partial property.
Or is the current behaviour expected and I'm missing or missunderstanding something?
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
Describe the bug 🐞
It looks like the named parameter ReadOnly of the ObservableAsProperty attribute is ignored when you use it at a partial property.
When you explicitly set ReadOnly to true the generated OAPH field isn't readonly and the same is true if you don't supply the parameter at all, this then also generates an OAPH field which isn't readonly and so in this regard is behaving different to specifying OAP attribute at a field without ReadOnly parameter which results in a readonly OAPH field.
I discovered that issue when looking into another issue which I reported here
Step to reproduce
[ObservableAsProperty]attribute and a field with[ObservableAsProperty]attribute[ObservableAsProperty(ReadOnly = true)]attribute and a field with[ObservableAsProperty(ReadOnly = true)]attributeObservableTestPropertyNotSetandObservableTestPropertyReadOnlyTrueare not readonly. When looking at the helper fields generated for the fields_observableTestFieldNotSetand_observableTestFieldReadOnlyTruethis is the case meaning both are readonly.Reproduction repository
https://github.com/DarkCloud14/ReactiveUI_SourceGen_ObservableAsProperty_ReadOnly_Issue
Expected behavior
I would expect that only if you explicitly set the named parameter ReadOnly of ObservableAsProperty attribute to false at a partial property the generated OAPH field isn't readonly and in the other two cases (not supplied at all or explicitly set to true) it is readonly.
The reason I would expect the above behaviour is because that's the result if you do that at a field instead of a partial property.
Or is the current behaviour expected and I'm missing or missunderstanding something?
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