Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ayo Adesina 424 posts 1006 karma points
    Feb 10, 2020 @ 12:19
    Ayo Adesina
    0

    How to convert IPublisedContent list to Strongly typed List - Model Builder.

    I'm using the Models Builder to create C# classes for all my document types, in my custom controller I am retriving all the content nodes that are of a specfic type:

    var viewModel = new HomePageViewModel(model);
    var caseStudyNodes = viewModel.Content.AncestorOrSelf().Descendants(CaseStudy.ModelTypeAlias).ToList();
    

    the caseStudyNodes variable is now a list of IPublished content. Is there a way to get this as a list of CaseStudy objects?

  • Michaël Vanbrabandt 863 posts 3346 karma points c-trib
    Feb 10, 2020 @ 12:27
    Michaël Vanbrabandt
    102

    Hi Ayo,

    try this:

    var caseStudyList = caseStudyNodes.Select(c => new CaseStudy(c));
    

    So basically you are going to select each IPublishedContent element and convert it to the strongly typed class CaseStudy.

    Have a nice day

    /Michaël

  • Ayo Adesina 424 posts 1006 karma points
    Feb 10, 2020 @ 12:35
    Ayo Adesina
    0

    ahh Of course!... Thanks Michael

  • Michaël Vanbrabandt 863 posts 3346 karma points c-trib
    Feb 10, 2020 @ 12:39
    Michaël Vanbrabandt
    0

    No problem!

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft