Issue when assigning same value for a property
Luigi6821 opened this issue · 2 comments
Hi,
I am using PropertyChanged feature in order to generate a proxy class when deserializing Json payload.
What I am facing is that when assigning same value to a property the PropertyChanged is not raised.
By contra if I define, for example, a class like the following in a traditional way (without using Fody):
`public class Person : INotifyPropertyChanged
{
private string name;
public event PropertyChangedEventHandler PropertyChanged;
public Person()
{
PropertyChanged += OnPropertyChanged;
}
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
}
public string Name
{
get
{
return name;
}
set
{
name = value;
OnPropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
}`
The OnPropertyChanged is correctly raised anytime I assign a value to Name property.
While if I use Fody and assign null to Name it does not raise OnPropertyChanged event.
Like in the following class:
`[AddINotifyPropertyChangedInterface]
public class Person1
{
private HashSet _memberChanged = new(StringComparer.OrdinalIgnoreCase);
protected void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
_memberChanged.Add(e.PropertyName);
}
public bool IsChanged(string memberName)
{
return _memberChanged.Contains(memberName);
}
public virtual string Name { get; set; }
}`
This is the code I used for testing
var person = new Person();
person.Name = null; // Correctly raise OnPropertyChangedEvent
var person1 = new Person1();
person1.Name = null; // Doesn't raise OnPropertyChangedEvent
Please help me.
Thanks in advance
PS: I noticed in the examples that what is going to be compiled using Fody is the following:
if (value != [currentPropertyValue])
{
// Raise notify property changed
}
Can we expand like the following ?
if (value != [currentPropertyValue] || notifyAlways)
notifyAlways could depends on Interface implemented:
public interface IAlwaysNotifyPropertyChanged : INotifyPropertyChanged
Thanks again
Thanks I found it !!