Skip to main content
Post Undeleted by Uri Agassi
after OP edit
Source Link
Uri Agassi
  • 1.8k
  • 11
  • 18

If I understand correctly, the sections list is a mixed list, containing Highlights and Tweets, and maybe other types.

I might suggest an approach where the Sections property returns List<Section>, but you could also add a FilterSection<T> which will return only the elements of the requested typeHow about using generics:

class DataSection<TCategoryData> where TCategoryData : CategoryData
{
 ...
     List<Section>string Sectionstype{get;set;}
 
     IEnumerable<T> FilterSections<T>() where T :ObservableCollection<TCategoryData> SectionbaseResults{get;set;}
 }


class HighlightSection : Section<Highlights> {}
          return Sections.OfType<T>();
  class TweetSection : }
Section<Tweets> ...
{}

If I understand correctly, the sections list is a mixed list, containing Highlights and Tweets, and maybe other types.

I might suggest an approach where the Sections property returns List<Section>, but you could also add a FilterSection<T> which will return only the elements of the requested type:

class Data
{
 ...
     List<Section> Sections{get;set;}
 
     IEnumerable<T> FilterSections<T>() where T : Section
     {
          return Sections.OfType<T>();
     }
 ...
}

How about using generics:

class Section<TCategoryData> where TCategoryData : CategoryData
{
    string type{get;set;}
    ObservableCollection<TCategoryData> baseResults{get;set;}
}


class HighlightSection : Section<Highlights> {}

class TweetSection : Section<Tweets> {}
Post Deleted by Uri Agassi
Source Link
Uri Agassi
  • 1.8k
  • 11
  • 18

If I understand correctly, the sections list is a mixed list, containing Highlights and Tweets, and maybe other types.

I might suggest an approach where the Sections property returns List<Section>, but you could also add a FilterSection<T> which will return only the elements of the requested type:

class Data
{
 ...
     List<Section> Sections{get;set;}

     IEnumerable<T> FilterSections<T>() where T : Section
     {
          return Sections.OfType<T>();
     }
 ...
}