Я пытаюсь создать некоторые интерфейсы. Объект IReportSection
будет иметь одну строку и набор элементов, которые могут отличаться в зависимости от того, с чем мы работаем. Мне нужно сделать его общим?Попытка разработать эти интерфейсы
IReport
будет иметь одну строку и коллекцию IReportSection
.
Вот как я пытаюсь определить его сейчас.
public interface IReport
{
string ReportName { get; set; }
ICollection<IReportSection> ReportSections { get; }
}
public interface IReportSection
{
string ReportSectionName { get; set; }
ICollection ReportItems { get; }
}
public abstract class ReportSectionBase : IReportSection
{
public string ReportSectionName { get; set; }
public ICollection ReportItems { get; set; }
}
И мои модели:
pulic class ProjectSubmissionViewModel
{
public int ProjectSubmissionId { get; set; }
public string SubmissionTitle { get; set; }
}
pulic class AffiliateViewModel
{
public int AffiliateId { get; set; }
public string AffiliateName { get; set; }
}
Это, как я пытаюсь использовать его в коде:
public class ChapterAffiliates : ReportSectionBase
{
public string ReportSectionName { get { return "Chapter Affiliates"; } }
public ICollection<AffiliateViewModel> ReportItems { get; set; }
}
public class ChapterTitles : ReportSectionBase
{
public string ReportSectionName { get { return "Chapter Titles"; } }
public ICollection<ProjectSubmissionViewModel> ReportItems { get; set; }
}
public class SubmissionListViewModel : IReport
{
public ICollection<ProjectSubmissionViewModel> Submissions { get; set; }
public ICollection<AffiliateViewModel> Affiliates{ get; set; }
public string ReportName { get; set; }
public ICollection<IReportSection> ReportSections
{
get
{
var affiliateSection = new ChapterAffiliates
{
ReportItems = Affiliates
};
var titleSection = new ChapterTitles
{
ReportItems = Submissions.Where(s => s.SubmissionTitle.Contains("SomePhrase")).ToList()
};
var sections = new List<IReportSection> { {subSection}, {titleSection} };
return sections;
}
}
}
Я не уверен, как лучше определить это. Я почти уверен, что сделал это раньше, но это не придет ко мне.
'IReport' нуждается в общем параметре' T': 'public interface IReport'. –
Lee
Открытый интерфейс IReport –
просто интересно, если вы сделаете его обобщенным, почему вы называете его отправкой отчетов? wouldnt, что подразумевает, что это всегда отчет –