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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:34:25+00:00 2026-05-14T01:34:25+00:00

I am trying out a little reflection and have a question on how the

  • 0

I am trying out a little reflection and have a question on how the cast the result object to an IList.

Here is the reflection:

private void LoadBars(Type barType)
{
    // foo has a method that returns bars
    Type foo = typeof(Foo);

    MethodInfo method = foo.GetMethod("GetBars")
        .MakeGenericMethod(bar);

    object obj = method.Invoke(foo, new object[] { /* arguments here */ });
    // how can we cast obj to an IList<Type> - barType
}

How can we cast the result of method.Invoke to an IList of Type from the barType argument?

  • 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-14T01:34:25+00:00Added an answer on May 14, 2026 at 1:34 am

    The point of a cast is usually to tell the compiler that you have some extra information – that you know something at compile time. You don’t know that information here – you only know it at execution time.

    What would you expect to do with the value after casting it? Admittedly there are some times when it would be useful – when you’ve got to use a generic interface, even if you want to get at members which don’t require the type parameter (e.g. Count in IList<T>). However, if that’s not what you’re trying to do it would really help if you could give more information.

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

Sidebar

Related Questions

This might be a little bit odd question, but Im trying to figure out
So I'm currently stuck on a little idea I'm trying out. Currently I have
I have found very little on this topic. I'm trying to work out a
I am trying to refactor out my application a little bit to keep it
I'm going a little nuts trying to figure out how to use template inheritance
I'm working on a little something and I am trying to figure out whether
Trying to practice ajax and PHP a little, I can't figure out why whenever
I've been trying to figure this out for a little while and I'm sure
I'm trying to roll out a little Rails plugin that is basically is just
I've been trying to figure out a little mystery now for a while, but

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.