Skip to content

CommandBase

Rico Suter edited this page Sep 8, 2015 · 4 revisions

An ICommand base implementation to use as base class for own command implementations.

Sample implementation:

public class DeletePersonCommand<Person> : CommandBase<Person>
{
	private IPersonRepository _personRepository; 
	
	public DeletePersonCommand(IPersonRepository personRepository)
	{
		_personRepository = personRepository;
	}
	
	public override bool CanExecute(object person)
	{
		return person != null && person is Person;
	}
	
	public override void Execute(object person)
	{
		_personRepository.DeletePerson((Person)person);
	}
}