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 445 posts 1059 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 3348 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 445 posts 1059 karma points
    Feb 10, 2020 @ 12:35
    Ayo Adesina
    0

    ahh Of course!... Thanks Michael

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

    No problem!

    /Michaël

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies