Fody: 6.5.1
PropertyChanged.Fody: 3.4.0
Describe the issue
The following code
[ObservableObject]
public partial class AnyViewModel
{
[ObservableProperty]
private string someField = "hey";
}
Generates the following code:
[GeneratedCode("Microsoft.Toolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "7.1.0.0")]
[DebuggerNonUserCode]
[ExcludeFromCodeCoverage]
public string SomeField
{
get
{
return someField;
}
set
{
if (!EqualityComparer<string>.Default.Equals(someField, value))
{
OnPropertyChanging(__KnownINotifyPropertyChangedOrChangingArgs.SomeFieldPropertyChangingEventArgs);
someField = value;
OnPropertyChanged(<>PropertyChangedEventArgs.SomeField);
OnPropertyChanged(__KnownINotifyPropertyChangedOrChangingArgs.SomeFieldPropertyChangedEventArgs);
}
}
}
- Any assignment of different values to
someField will generate a duplicate PropertyChanged event.
Settings [PropertyChanged.DoNotNotify] on the field has no effects (obviously).
Minimal Repro
- Copy paste the example above in any WPF project using Microsoft.MVVM.Toolkit.
- Compile.
- Look at the IL.
Make an effort to fix the bug
Maybe the generator should see that a (oddly) placed call to the OnPropertyChanged already exists and therefore not emit one?
Or should [PropertyChanged.DoNotNotify] be extended to also work on fields? For some reason the flags already indicate that it can be set on fields but it has no effect.
Fody: 6.5.1
PropertyChanged.Fody: 3.4.0
Describe the issue
The following code
Generates the following code:
someFieldwill generate a duplicatePropertyChangedevent.Settings
[PropertyChanged.DoNotNotify]on the field has no effects (obviously).Minimal Repro
Make an effort to fix the bug
Maybe the generator should see that a (oddly) placed call to the
OnPropertyChangedalready exists and therefore not emit one?Or should
[PropertyChanged.DoNotNotify]be extended to also work on fields? For some reason the flags already indicate that it can be set on fields but it has no effect.