// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Commands
{
using System;
using System.Windows.Input;
public class SimpleRelayCommand : ICommand
{
private Action command;
private Func canExecute;
public SimpleRelayCommand(Action commandAction, Func canExecute = null)
{
this.command = commandAction;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return this.canExecute == null ? true : this.canExecute();
}
public void Execute(object parameter)
{
if (this.command != null)
{
if (typeof(T) == typeof(int))
{
parameter = int.Parse(parameter.ToString() ?? string.Empty);
}
this.command((T)parameter);
}
}
public event EventHandler CanExecuteChanged;
}
}