You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've avoided upgrading since 3.1.3 due to a behaviour change in 3.2.0 which introduces bugs in my code. It would be good to know if the change was intentional.
With 3.1.3 the code below prints: Length changed to 3
Name changed to One
If I upgrade to 3.2.0: Name changed to One
This seems to be because >= 3.2.0 has stopped calling On-PropName-Changed for dependencies. It looks like a property changed event is raised for the dependent property, but not the associated On-Property-Changed method;
static void Main(string[] args)
{
Thing thing = new Thing();
thing.Name = "One";
}
[AddINotifyPropertyChangedInterface]
public class Thing
{
public string Name { get; set; }
public int Length => Name?.Length ?? 0;
private void OnNameChanged() => Console.WriteLine($"Name changed to {Name}");
private void OnLengthChanged() => Console.WriteLine($"Length changed to {Length}");
}
The text was updated successfully, but these errors were encountered:
Hmm I don't think that was an intentional change...
The build produces the following warning:
Warning : Fody/PropertyChanged: Type ConsoleApp.Thing does not contain a Length property with an injected change notification, and therefore the OnLengthChanged method will not be called. You can suppress this warning with [SuppressPropertyChangedWarnings].
And here's the setter of Name:
[CompilerGenerated]
set
{if(string.Equals(this.<Name>k__BackingField,value,StringComparison.Ordinal)){return;}this.<Name>k__BackingField=value;this.<>OnPropertyChanged(<>PropertyChangedEventArgs.Length);this.OnNameChanged();this.<>OnPropertyChanged(<>PropertyChangedEventArgs.Name);}
So it sees there is no setter for Length, therefore no possible call to OnLengthChanged(), and incorrectly concludes that a call to OnLengthChanged() shouldn't be generated elsewhere, ie in the Name setter.
I see if I change the Length property to the following, it will work:
public int Length { get => Name?.Length ?? 0; set { } }
Looks like it was the following revision which introduced the problem. I'm going to have a look and see if there is anything I can do, but I've not looked at the code before so there's no telling how it will go.
I've avoided upgrading since 3.1.3 due to a behaviour change in 3.2.0 which introduces bugs in my code. It would be good to know if the change was intentional.
With 3.1.3 the code below prints:
Length changed to 3
Name changed to One
If I upgrade to 3.2.0:
Name changed to One
This seems to be because >= 3.2.0 has stopped calling On-PropName-Changed for dependencies. It looks like a property changed event is raised for the dependent property, but not the associated On-Property-Changed method;
The text was updated successfully, but these errors were encountered: