jeudi 22 février 2018

Cast to IEnumerable

This is a weird problem that I've stumbled upon, involving reflection:

I create a MyGenericType<T> at runtime where T is a runtime type:

object genType = Activator.CreateInstance(typeof(MyGenericType<>).MakeGenericType(runtimeType));

Then I need to pass it as an argument to another function which only accepts a IEnumerable<runtimeType>.

I can't use dynamic as MyGenericType only implements IEnumerable explicitly, not implicitly.

Is there anyway to cast to an IEnumerable<runtimeType>?





Aucun commentaire:

Enregistrer un commentaire