/// <summary> /// Fires the PropertyChanged event for the <paramref name="property"/>. /// </summary> /// <typeparam name="T">Any object</typeparam> /// <param name="sender">The INotifyPropertyChangedExtension implementor</param> /// <param name="handler">The PropertyChanged event</param> /// <param name="original">Reference to the current value of the <paramref name="property"/></param> /// <param name="value">Requested new value of the <paramref name="property"/></param> /// <param name="property">The name of the property</param> /// <returns>Returns <c>true</c> if the event is fired successfully. Otherwise returns <c>false</c>.</returns> public static bool SetProperty <T>(this INotifyPropertyChangedExtension sender, ref T original, T value, [CallerMemberName] string property = null) { if (NpcExtensions.AreValuesEqual(original, value)) { return(false); } else { original = value; return(sender.FirePropertyChanged(new PropertyChangedEventArgs(property))); } }
/// <summary> /// Sets a property to a new value and fires the PropertyChanged event. /// </summary> /// <typeparam name="T">Type of the property</typeparam> /// <param name="sender">The Caller.</param> /// <param name="handler">The event.</param> /// <param name="original">The original property value.</param> /// <param name="value">The new value.</param> /// <param name="property">The name of the property being changed.</param> /// <returns>Returns <c>true</c> if the property is set and the property changed event fires. Returns <c>false</c> if <paramref name="original"/> equals <paramref name="value"/>.</returns> public static bool SetProperty <T>(INotifyPropertyChanged sender, PropertyChangedEventHandler handler, ref T original, T value, [CallerMemberName] string property = null) { if (NpcExtensions.AreValuesEqual(original, value)) { return(false); } else { original = value; handler?.Invoke(sender, new PropertyChangedEventArgs(property)); return(true); } }