You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1022 B
26 lines
1022 B
// Author: Gockner, Simon
|
|
// Created: 2021-04-06
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using System;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
using Avalonia.Controls;
|
|
using ReactiveUI;
|
|
|
|
namespace Mystify.ViewModels
|
|
{
|
|
public class ViewModelBase : ReactiveObject
|
|
{
|
|
protected bool IsInDesignMode => Design.IsDesignMode;
|
|
protected void RaisePropertyChanged(string propertyName) => ((IReactiveObject) this).RaisePropertyChanged(propertyName);
|
|
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
|
|
{
|
|
if (propertyExpression.Body is not MemberExpression body)
|
|
throw new ArgumentException("Invalid argument.", nameof(propertyExpression));
|
|
|
|
PropertyInfo propertyInfo = body.Member as PropertyInfo ?? throw new ArgumentException("Argument is not a property.", nameof(propertyExpression));
|
|
((IReactiveObject) this).RaisePropertyChanged(propertyInfo.Name);
|
|
}
|
|
}
|
|
}
|
|
|