Overridden properties no longer notified in 3.2.10
See original GitHub issueI just updated a solution from Fody 2.6.1 and noticed different behavior in overridden properties. I checked a bunch of different versions and it starts happening when I upgrade from 3.2.9 to 3.2.10. That version made some changes regarding overridden properties.
PropertyChanged is the only weaver I’m using, the solution uses MSBuild 16, but the projects target .NET 4.7.2.
I don’t know what’s going wrong, so let me explain what I’m doing. I have a base, a folder, file and configuration. A folder contains multiple files as children, a file contains multiple configurations as children. Changes in children bubble up to their parent. That’s possibly not relevant, but I’ve added it to the repro at the bottom.
The base. (BaseViewModel only implements INotifyPropertyChanged)
internal class BaseFastenerViewModel : BaseViewModel
{
public virtual Enums.FastenerType FastenerType { get; set; }
}
Folder:
internal class FolderViewModel : BaseFastenerViewModel
{
private Enums.FastenerType _fastenerType;
public override Enums.FastenerType FastenerType
{
get => _fastenerType;
set
{
_fastenerType = value;
if (value == Enums.FastenerType.Multiple || _skipUpdatingFastenerTypeOnChildren) return;
foreach (var child in Children) child.FastenerType = value;
}
}
public ObservableCollection<BaseFastenerViewModel> Children { get; }
}
File
internal class FileViewModel : BaseFastenerViewModel
{
private Enums.FastenerType _fastenerType;
public override Enums.FastenerType FastenerType
{
get => _fastenerType;
set
{
_fastenerType = value;
if (value == Enums.FastenerType.Multiple || _skipUpdatingFastenerTypeOnChildren) return;
foreach (var child in Children) child.FastenerType = value;
}
}
public ObservableCollection<ConfigurationViewModel> Children { get; private set; } = new ObservableCollection<ConfigurationViewModel>();
}
The relevant section of the resulting code for FileViewModel in 2.6.1 up to 3.2.9 according to .NET Reflector:
And in 3.2.10:
I created a small project where I can reproduce it: https://github.com/brinkdinges/fody-propertychanged-repro/tree/master/PropertyChanged
Regarding being a Patron; I just made my company CAD Booster one.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
We did the check in the setter, but only if (any).set_Property() is called, so it interpreted child.set_Property as a call to base.set_Property, thus omitting the change notification.
I think this sample should work out of the box - we had added a check if the setter calls the base class setter, and, if not, it should notify.
I’ll have a look next weekend, to see what’s going wrong here.