title: How can I simplify the implementation of Commands in ViewModels for WPF/MVVM?
body: <p>I have noticed that I am repeating a lot of code when implementing Commands on ViewModels for a MVVM-WPF scenario. The standard implementation, as shown below, consists of a public readonly field of type <code>ICommand</code>, a private <code>DelegateCommand</code> field and a method for the execution logic. <code>DelegateCommand</code> gets initialized in the <code>ICommand</code>s get-accessor.</p>
  
  <p>How can this approach be condensed, considering the repetition for every command? </p>
  
  <pre class="lang-cs prettyprint-override"><code>private DelegateCommand saveCommand;
  private DelegateCommand commandClearInputFileList;
  private DelegateCommand commandInputFilesDeleteSelected;
  
  public ICommand SaveCommand {
      get {
          if (saveCommand == null) {
              saveCommand = new DelegateCommand(CommitDataBasePush);
          }
          return saveCommand;
      }
  }
  
  public ICommand CommandClearInputFileList {
      get {
          if (commandClearInputFileList == null) {
              commandClearInputFileList = new DelegateCommand(InputFilesClear);
          }
          return commandClearInputFileList;
      }
  }
  
  public ICommand CommandInputFilesDeleteSelected {
      get {
          if (commandInputFilesDeleteSelected == null) {
              commandInputFilesDeleteSelected = new DelegateCommand(InputFilesDeleteSelected);
          }
          return commandInputFilesDeleteSelected;
      }
  }
  </code></pre>