Hi,
I get an IEnumerable which I know is a object array. I also know the datatype of the elements. Now I need to cast this to an IEnumerable<T
>, where T is a supplied type. For instance
IEnumerable results = GetUsers();
Type t = GetType(); //Say this returns User
IEnumerable<T> users = ConvertToTypedIEnumerable(results, t);
I now want to cast/ convert this to IEnumerable<User
>. Also, I want to be able to do this for any type.
I cannot use IEnumerable.Cast<>, because for that I have to know the type to cast it to at compile time, which I don't have. I get the type and the IEnumerable at runtime.
- Thanks