I have a collection (IQueryable<object>/IEnumerable<object>
) and a given Type
that I get by reflection at runtime. How can I cast the IQueryable<object>
to the specific Type
when:
- The
Type
is a class e.g.Person
(and I want to make a cast of theIQueryable<object>
toIQueryable<Person>
) - The
Type
is a generic collection e.g.IQueryable<Person>
Note that Type is a variable that I get through aVariable.GetType(). I do not know the type beforehand, therefore I cannot use Cast<type>
nor (type).