using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Crysome.Server.ViewModel;

public abstract class ViewModelBase : INotifyPropertyChanged
{
	public event PropertyChangedEventHandler PropertyChanged;

	public virtual void OnPropertyChanged(string propertyName)
	{
		PropertyChangedEventHandler propertyChangedEventHandler = this.PropertyChanged;
		if (propertyChangedEventHandler != null)
		{
			PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
			propertyChangedEventHandler(this, e);
		}
	}

	public virtual void OnPropertyChanged<T>(Expression<Func<T>> propertyNameExpression)
	{
		OnPropertyChanged(((MemberExpression)propertyNameExpression.Body).Member.Name);
	}
}
