C# - Cast object to IList<T> based on Type

Posted by blu on Stack Overflow See other posts from Stack Overflow or by blu
Published on 2010-03-22T14:57:52Z Indexed on 2010/03/22 15:01 UTC
Read the original article Hit count: 538

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection