Created
January 24, 2016 15:40
-
-
Save BrianJVarley/4a0890b678e037296aba to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ParkingTagPicker.DAL; | |
using ParkingTagPicker.ExtensionMethods; | |
using ParkingTagPicker.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Input; | |
using Windows.ApplicationModel.Chat; | |
namespace ParkingTagPicker.ViewModels | |
{ | |
public abstract class ViewModelBase : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected void RaisePropertyChanged(string propertyName) | |
{ | |
var propertyChanged = this.PropertyChanged; | |
if (propertyChanged != null) | |
{ | |
propertyChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
protected bool SetProperty<T>(ref T backingField, T Value, Expression<Func<T>> propertyExpression) | |
{ | |
var changed = !EqualityComparer<T>.Default.Equals(backingField, Value); | |
if (changed) | |
{ | |
backingField = Value; | |
this.RaisePropertyChanged(ExtractPropertyName(propertyExpression)); | |
} | |
return changed; | |
} | |
private static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression) | |
{ | |
var memberExp = propertyExpression.Body as MemberExpression; | |
if (memberExp == null) | |
{ | |
throw new ArgumentException("Expression must be a MemberExpression.", "propertyExpression"); | |
} | |
return memberExp.Member.Name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment