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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:27:41+00:00 2026-05-12T11:27:41+00:00

I need to be able to access a property via reflection, and, knowing that

  • 0

I need to be able to access a property via reflection, and, knowing that this property is an IEnumerable, append an object to it.

Something like this:

Object o;
MemberInfo m;

Array arr; // Except use IEnumerable, may have to take account of value/ref types
arr = (Array)((PropertyInfo)m).GetValue(o, null); }

List<o.GetType()> newArr = new List<o.GetType()>(); /* fails */
newArr.AddRange(arr);
newArr.Add(o);

((PropertyInfo)m).SetValue(o, newArr.ToArray(), null);

Can you help me where I’m going wrong 🙂

Solution:

See accepted answer comments. Also (Get the actual type of a generic object parameter) is of help.

  • 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-12T11:27:41+00:00Added an answer on May 12, 2026 at 11:27 am

    It sounds like you’re essentially asking how to make a List<T> based on an unknown-at-compile-time type. For this you’ll have to use a bit more reflection magic:

    Type genericListType = typeof(List<>);
    Type listType = genericListType.MakeGenericType(o.GetType());
    object listInstance = Activator.CreateInstance(listType);
    

    That would create a List<T> out of a runtime type.

    But really, your code would be much simpler if you simply use ArrayList:

    ArrayList list = new ArrayList(arr);
    list.Add(o);
    Array newArray = list.ToArray(o.GetType());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file as documentRoot/app/webroot/myFile.php I need to be able to access this
Say I have an interface that has as property another interface. Something like: interface
I need to be able to access a list throughout my Rails project. For
I need my app to be able access an third party API who limits
I'm using an object from a 3rd party API that has a property of
I need to access an excel file that is already open. I thought just
From an ASP.Net C# application I need to access the 'Title' property value from
From an ASP.Net C# application I need to access the 'Title' property value from
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.