using System; using System.ComponentModel; using System.Windows.Input; namespace Tasklight.Controller { public abstract class ModelBase : PropertyChangedBase { public void SetProperty(ref T storage, T value, string name) { //if (storage == null) //throw new InvalidCastException("osrs_toolbox.ModelBase.UpdateProperty\nStorage cannot be null."); if (value == null) throw new InvalidCastException("ModelBase.UpdateProperty\nValue cannot be null."); //if (storage.GetType() != value.GetType()) //throw new InvalidCastException("osrs_toolbox.ModelBase.UpdateProperty\nVariable type mismatch between storage and value."); storage = value; OnPropertyChanged(name); } } public abstract class PropertyChangedBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } public class RelayCommand : ICommand { private Action execute; private Func? canExecute; public event EventHandler? CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public RelayCommand(Action execute, Func? canExecute = null) { this.execute = execute; this.canExecute = canExecute; } public bool CanExecute(object? parameter) { return this.canExecute == null || this.canExecute(parameter); } public void Execute(object? parameter) { this.execute(parameter); } } }