Skip to content

CommandBase

Rico Suter edited this page Jun 3, 2015 · 4 revisions

An ICommand base implementation to use as base class for own command implementations when using the command pattern.

Sample implementation:

public class DeletePersonCommand<Person> : CommandBase<Person>
{
 private DataRepository _dataRepository; 

 public DeletePersonCommand(DataRepository dataRepository)
 {
  _dataRepository = dataRepository;
 }

 public override bool CanExecute(object person)
 {
  return person # = null && person is Person;
 }

 public override void Execute(object person)
 {
  _dataRepository.DeletePerson((Person)person);
 }
}
Clone this wiki locally