16 個のボタンがある WPF フォームがあります。ビュー モデルを初期化するときに、16 個すべてを RelayCommand オブジェクトとして設定する必要があります。私の Initialize() メソッドが行うことはこれだけですが、コード分析エラー CA1502:AvoidExcessiveComplexity が発生します。
これは CA 警告を抑制する良いケースですか、それとも CA 違反を引き起こさずにこれらのコマンドを設定するより洗練された方法はありますか?
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Simply setting the commands")]
private void Initialize()
{
this.AddApplicationCommand = new RelayCommand(_ => AddApplication());
this.DeleteApplicationCommand = new RelayCommand(_ => DeleteApplication(), _ => ApplicationIsSelected);
this.RefreshApplicationsCommand = new RelayCommand(_ => RefreshApplications());
this.SaveApplicationCommand = new RelayCommand(_ => SaveApplication(), _ => ApplicationIsSelected);
this.ForceInstallationCommand = new RelayCommand(_ => ForceInstallation(), _ => ApplicationIsSelected);
this.DeleteForceInstallationCommand = new RelayCommand(_ => DeleteForceInstallation(), _ => ApplicationIsSelectedAndForceExists());
this.AddTaskCommand = new RelayCommand(_ => AddTask(), _ => ApplicationIsSelected);
this.EditTaskCommand = new RelayCommand(_ => EditTask(), _ => TaskIsSelected());
this.DeleteTaskCommand = new RelayCommand(_ => DeleteTask(), _ => TaskIsSelected());
this.ImportTasksCommand = new RelayCommand(_ => ImportTasks(), _ => ApplicationIsSelected);
this.ExportTasksCommand = new RelayCommand(_ => ExportTasks(), _ => TaskIsSelected());
this.ImportLegacyTasksCommand = new RelayCommand(_ => ImportLegacyTasks(), _ => ApplicationIsSelected);
this.MoveTaskUpCommand = new RelayCommand(_ => MoveRowUp(), _ => TaskIsSelected());
this.MoveTaskDownCommand = new RelayCommand(_ => MoveRowDown(), _ => TaskIsSelected());
this.AddVariableGroupCommand = new RelayCommand(_ => AddVariableGroup());
this.RemoveVariableGroupCommand = new RelayCommand(_ => RemoveVariableGroup(), _ => VariableGroupIsSelected());
}