I have:
class Car {..} class Other{   List<T> GetAll(){..} }   I want to do:
Type t = typeof(Car); List<t> Cars = GetAll<t>();   How can I do this?
I want to return a generic collection from the database of a type that I discover at runtime using reflection.
Type generic = typeof(List<>);     Type specific = generic.MakeGenericType(typeof(int));     ConstructorInfo ci = specific.GetConstructor(Type.EmptyTypes);     object o = ci.Invoke(new object[] { }); 
                        You could use reflection for this:
Type t = typeof(Car); System.Type genericType= generic.MakeGenericType(new System.Type[] { t}); Activator.CreateInstance(genericType, args); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With