Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 500273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:04:13+00:00 2026-05-13T06:04:13+00:00

In my CMS I have a load of modules which allow me to do

  • 0

In my CMS I have a load of modules which allow me to do some clever item listing stuff. I am trying to use them to pull out a list of their child objects via reflection, but am getting stuck with the level of generics involved.

I have got as far as this method:

var myList = moduleObj.GetType().GetMethod("ChildItems").Invoke(moduleObj, new object[] { });

which returns a List. Each modulespecificobject is bound it an IItemListable interface which has the methods in it I am trying to access.

I am unsure how I can cast or iterate the myList object as a set of IItemListable objects access the methods required.

Thanks

A few of the classes:

public interface IItemListable
{
    IQueryable GetQueryableList();
    string GetIDAsString();
    IItemListable GetItemFromUrl(string url, List<IItemListable> additionalItems);
    bool IsNewItem();
    IItemListable CreateItem<T>(ItemListerControl<T> parentList) where T : class, IItemListable;
    IItemListable LoadItem(string id);
    IItemListable SaveItem();
    RssToolkit.Rss.RssItem ToRssItem();
    void DeleteItem();
    string ItemUrl();
}

public interface IItemListModule<T> where T: IItemListable
{
    List<T> ChildItems();
}


public class ArticlesModule : ItemListModuleBase<Article>, IItemListModule<Article>
{
    #region IItemListModule<Article> Members

    public new List<Article> ChildItems()
    {
        return base.ChildItems().Cast<Article>().Where(a => a.IsLive).ToList();
    }

    #endregion
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:04:14+00:00Added an answer on May 13, 2026 at 6:04 am

    You can direct cast while iterating:

    IList myList = (IList)moduleObj.GetType().GetMethod(
                 "ChildItems").Invoke(moduleObj, new object[] { });
    foreach (IItemListable o in myList)
    {
    
    }
    

    Edit: I would better mark ChildItems as virtual in the base then you could write

    public override List<Article> ChildItems()
    {
      return base.ChildItems().Where(a => a.IsLive).ToList();
    }
    

    and

    var myList = moduleObj.ChildItems();
    foreach (IItemListable o in myList)
    {
    }
    

    without any need to cast, avoiding the use of the new keyword and without having to use reflection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a CMS which has several thousand text/html files in it. It turns
I have created a website using vbulletin i have installed CMS and BLOG modules
I'm going to develop a website which uses ajax to load pages. The cms
$id = 'unique_id_block'; $cmsBlockModel = Mage::getResourceModel('cms/block'); $block = Mage::getModel('cms/block'); $cmsBlockModel->load($block, $id); I have the
I am trying to integrate cpanel to my cms... I have this code to
I have a requirement to load text labels from our CMS. The content is
I have a large custom CMS and I use xcode to run a profiler
I have to use tinymce as a wysiwyg editor in a CMS to populate
I have an existing django application, with which I need to integrate django-cms. Django-cms
I'm currently trying to use cakephp to create my own small CMS in php.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.