title: Code Analysis AvoidExcessiveComplexity - Just Setting Commands
body: <p>I have a WPF form with 16 buttons on it. When my view model initializes, I need to set all 16 as RelayCommand objects. This is all my Initialize() method does, yet that causes the code analysis error CA1502:AvoidExcessiveComplexity.</p>
  
  <p>Is this a good case for suppressing a CA warning, or is there a more elegant way to set these commands without causing the CA violation?</p>
  
  <pre><code>[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Simply setting the commands")]
  private void Initialize()
  {
      this.AddApplicationCommand      = new RelayCommand(_ =&gt; AddApplication());
      this.DeleteApplicationCommand   = new RelayCommand(_ =&gt; DeleteApplication(), _ =&gt; ApplicationIsSelected);
      this.RefreshApplicationsCommand = new RelayCommand(_ =&gt; RefreshApplications());
      this.SaveApplicationCommand     = new RelayCommand(_ =&gt; SaveApplication(), _ =&gt; ApplicationIsSelected);
  
      this.ForceInstallationCommand       = new RelayCommand(_ =&gt; ForceInstallation(), _ =&gt; ApplicationIsSelected);
      this.DeleteForceInstallationCommand = new RelayCommand(_ =&gt; DeleteForceInstallation(), _ =&gt; ApplicationIsSelectedAndForceExists());
  
      this.AddTaskCommand            = new RelayCommand(_ =&gt; AddTask(), _ =&gt; ApplicationIsSelected);
      this.EditTaskCommand           = new RelayCommand(_ =&gt; EditTask(), _ =&gt; TaskIsSelected());
      this.DeleteTaskCommand         = new RelayCommand(_ =&gt; DeleteTask(), _ =&gt; TaskIsSelected());
      this.ImportTasksCommand        = new RelayCommand(_ =&gt; ImportTasks(), _ =&gt; ApplicationIsSelected);
      this.ExportTasksCommand        = new RelayCommand(_ =&gt; ExportTasks(), _ =&gt; TaskIsSelected());
      this.ImportLegacyTasksCommand  = new RelayCommand(_ =&gt; ImportLegacyTasks(), _ =&gt; ApplicationIsSelected);            
      this.MoveTaskUpCommand         = new RelayCommand(_ =&gt; MoveRowUp(), _ =&gt; TaskIsSelected());
      this.MoveTaskDownCommand       = new RelayCommand(_ =&gt; MoveRowDown(), _ =&gt; TaskIsSelected());
  
      this.AddVariableGroupCommand    = new RelayCommand(_ =&gt; AddVariableGroup());
      this.RemoveVariableGroupCommand = new RelayCommand(_ =&gt; RemoveVariableGroup(), _ =&gt; VariableGroupIsSelected());
  }
  </code></pre>