Created
December 5, 2019 00:41
-
-
Save icebeam7/d2319ef16b7a6ea2f004025c33c16230 to your computer and use it in GitHub Desktop.
HarryPotterApp: BaseViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
namespace HarryPotterApp.ViewModels | |
{ | |
public class BaseViewModel : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs((propertyName))); | |
} | |
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName]string propertyName = null) | |
{ | |
if (EqualityComparer<T>.Default.Equals(storage, value)) | |
{ | |
return false; | |
} | |
storage = value; | |
OnPropertyChanged(propertyName); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment