c# - Trying to work out these interfaces -


i'm trying create interfaces. ireportsection object have 1 string , collection of items, different depending on we're working with. need make generic?

the ireport have 1 string , collection of ireportsection.

here's how i'm trying define now.

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; } }  

and models:

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; } } 

this how i'm trying use in code:

public class chapteraffiliates : reportsectionbase {     public string reportsectionname { { return "chapter affiliates"; } }      public icollection<affiliateviewmodel> reportitems { get; set; } }  public class chaptertitles : reportsectionbase {     public string reportsectionname { { 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     {                 {             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;          }     } } 

i'm not sure how best define this. i'm pretty sure i've done before, it's not coming me.

are type parameters trtype same within report? e.g. have report sections different report types in them?

if types within report same, solution relatively simple:

public interface ireport<t> { ... } 

if not case - you'll have different, e.g:

public interface ireportsection {     string reportsectionname { get; }      icollection reportitems { get; } }  public abstract class reportsectionbase<trtype> : ireportsection {    ... }  

this allows put different underlying types in reportsections collection related report. you'll have more work exact information need out of each report section.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -