I have a WinForms project that uses the Passive View MVP pattern. In the Presenter of one of my Views I have a function that gets questions and from its Model. But I want to make sure these collections are not empty so that I can inform the user when they are. Right now my code seems very ugly and I wonder if anyone has any tips to make it shorter/better. Thank you.
public void InitializeInterview(object sender, EventArgs e)
{
List<List<string>> questionList = new List<List<string>>();
List<List<string>> maturityAnswerList = new List<List<string>>();
List<List<string>> complianceAnswerList = new List<List<string>>();
questionList = _model.GetQuestions();
maturityAnswerList = _model.GetMaturityAnswers();
complianceAnswerList = _model.GetComplianceAnswers();
if (questionList != null && questionList.Any())
{
_view.Questions = questionList;
}
else
{
_view.Message("No questions have been found, please add a new question standard");
_view.CloseView();
}
if (maturityAnswerList != null && maturityAnswerList.Any())
{
_view.MaturityAnswers = maturityAnswerList;
}
else
{
_view.Message("No maturity answers have been found, please add a new maturity standard");
_view.CloseView();
}
if (complianceAnswerList != null && complianceAnswerList.Any())
{
_view.ComplianceAnswers = complianceAnswerList;
}
else
{
_view.Message("No compliance answers have been found, please add a new compliance standard");
_view.CloseView();
}
}