Minor codegen improvement in SetProperty with Action<T>

This commit is contained in:
Sergio Pedri
2020-09-03 12:55:44 +02:00
parent 0abb94fbc5
commit 798ea71ce1
@@ -136,7 +136,19 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel
/// </remarks>
protected bool SetProperty<T>(T oldValue, T newValue, Action<T> callback, [CallerMemberName] string? propertyName = null)
{
return SetProperty(oldValue, newValue, EqualityComparer<T>.Default, callback, propertyName);
// We avoid calling the overload again to ensure the comparison is inlined
if (EqualityComparer<T>.Default.Equals(oldValue, newValue))
{
return false;
}
OnPropertyChanging(propertyName);
callback(newValue);
OnPropertyChanged(propertyName);
return true;
}
/// <summary>