CommunityToolkit / CommunityToolkit/dotnet
Inherited ViewModels can hide important warnings
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
If an `ObservableProperty` is created in two ViewModels, a parent and child, then the parent property gets hidden and the warning is blocked from the user.
### Regression
_No response_
### Steps to reproduce
```text
For this code:
public partial class ParentViewModel : ObservableObject
{
[ObservableProperty] private int _someValue;
public int AnotherValue { get; set; }
}
public partial class DerivedViewModel : ParentViewModel
{
[ObservableProperty] private int _someValue;
public int AnotherValue { get; set; }
}
The following warning is generated:
> 'DerivedViewModel.AnotherValue' hides inherited member 'ParentViewModel.AnotherValue'. Use the new keyword if hiding was intended.
```
### Expected behavior
The following warning should also be generated:
> 'DerivedViewModel.SomeValue' hides inherited member 'ParentViewModel.SomeValue'. Use the new keyword if hiding was intended.
### Screenshots
_No response_
### IDE and version
VS 2022
### IDE version
17.3.0
### Nuget packages
- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)
### Nuget package version(s)
8.0.0
### Additional context
This is due to warnings being disabled with
```cs
#pragma warning disable
```
Fix options:
1. The pragma is enabled for this warning
- Pros: Warning might alert the user to unintended functionality
- Cons: User can't suppress the warning
2. Option 1 plus `ObservableProperty` is modified to accept a parameter that says whether hiding is desired
- Pros: The warning is exposed and can be suppressed
- Cons: May not be worth the complication
### Help us help you
Yes, I'd like to be assigned to work on this item
Contributor guide
Assessment
This issue has not been assessed yet.