I have a large number of classes.
From this list I get a specified type
Type aType = Type.GetType(...);
Now I want to use this type in a linq statement like:
var aResult = from obj in scope.Extent<aType>() select obj;
This does not seem to be possible, as Extent does not accept Type.
Is there any way now (with .net 4.5) to call the statement?
All I want to do is to say use Type as class. Don’t invoke the class, only get with linq all objects of this type from a scope.
You can’t use an instance of
Typeas a generic type argument – not at compile time, anyway.If you want objects of a specific type, you could do
Note that this requires an exact type match, rather than any kind of “can be assigned to” relationship.
Also note that this will only get you a series of
objects – again there’s no compile-time way to cast things to an instance ofType.