Create a Generic IEnumerable<T> given a IEnumerable and the member datatypes
- by ilias
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();
IEnumerable<T> users = ConvertToTypedIEnumerable(results, typeof(User));
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