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 120563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:49:52+00:00 2026-05-11T03:49:52+00:00

Through reflection, is there some way for me to look at a generic List’s

  • 0

Through reflection, is there some way for me to look at a generic List’s contained type to see what type the collection is of? For example:

I have a simple set of business objects that derive from an interface, like this:

public interface IEntityBase{}    public class BusinessEntity : IEntityBase    {     public IList<string> SomeStrings {get; set;}            public IList<ChildBusinessEntity> ChildEntities { get; set;} }   public class ChildBusinessEntity : IEntityBase{} 

In the case where I am iterating through the properties of BusinessEntity through reflection, would there be a way for me to see if the objects nested inside those lists derived from IEntityBase?

Pseudocoded (badly) like this:

foreach(PropertyInfo info in typeof(BusinessEntity).GetProperties()) {   if(info.PropertyType is GenericIList &&      TheNestedTypeInThisList.IsAssignableFrom(IEntityBase)   {     return true;   } } 

Only option I’ve heard so far, that works, would be to pull out the first item from that list, then look at its type. Any easier way (especially because I can’t be guaranteed that the List won’t be empty)?

  • 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. 2026-05-11T03:49:53+00:00Added an answer on May 11, 2026 at 3:49 am

    Assuming you have the System.Type which describes your List<>, you can use the Type.GetGenericArguments() method to get the Type instance which describes what it’s a list of.

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

Sidebar

Related Questions

Is there a way to iterate (through foreach preferably) over a collection using reflection?
I have a class which has some properties of type List<float> , List<int> etc.
The title pretty much says it all. When I'm doing some reflection through my
I'm using reflection to loop through a Type 's properties and set certain types
I have found this example on StackOverflow: var people = new List<Person> { new
I'm wondering is there a way to retrieve the type hinting associated with attributes
Through profiling I've discovered that the sprintf here takes a long time. Is there
Through some bungling in creating and removing publications, I was left with a lot
Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks
I have an issue with .Net reflection. The concept is fairly new to me

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.