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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:23:25+00:00 2026-05-21T17:23:25+00:00

I have come across something pretty complex. I would be obliged if anyone can

  • 0

I have come across something pretty complex. I would be obliged if anyone can help.

1) I have to create a List<> of unknown type at compile time. That I have already achieved.

 Type customList = typeof(List<>).MakeGenericType(tempType);
 object objectList = (List<object>)Activator.CreateInstance(customList);

“temptype” is the custom type thats been already fetched.

2) Now I have PropertyInfo object which is that list from which I have to copy all items to the the instance that I have just created “objectList”

3) Then I need to iterate and access the items of “objectList” as if it were a “System.Generic.List”.

Cutting long story short, using reflection I need to extract a property that is a list and have it as an instance for further use. Your suggestions would be appreciated. Thanks in Advance.

Umair

  • 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-21T17:23:26+00:00Added an answer on May 21, 2026 at 5:23 pm

    Many of the .NET generic collection classes also implement their non-generic interfaces. I’d make use of these to write your code.

    // Create a List<> of unknown type at compile time.
    Type customList = typeof(List<>).MakeGenericType(tempType);
    IList objectList = (IList)Activator.CreateInstance(customList);
    
    // Copy items from a PropertyInfo list to the object just created
    object o = objectThatContainsListToCopyFrom;
    PropertyInfo p = o.GetType().GetProperty("PropertyName");
    IEnumerable copyFrom = p.GetValue(o, null);
    foreach(object item in copyFrom) objectList.Add(item); // Will throw exceptions if the types don't match.
    
    // Iterate and access the items of "objectList"
    // (objectList declared above as non-generic IEnumerable)
    foreach(object item in objectList) { Debug.WriteLine(item.ToString()); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just come across something that is quite strange and yet I haven't
I have come across the following type of code many a times, and I
I have come across a problem I just can't solve. I am using autocomplete
I'm new to PHP (and web development in general) and have come across something
I have come across something very similar to the following when looking for basic,
I'm porting an application from VB6 to VB.NET and have come across something that
gcc 4.4.1 I am maintaining someone's code and I have come across something that
I'm working on a blog in PHP/SQL etc and I have come across something
i've been experimenting with javascript's prototypal inheritance and have come across something that perhaps
just come across something I've never came across before. I have a value in

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.