Im getting slightly confused by a C# error.
Type t = thing.GetType()
t
is now a type. but if i attempt to do this:
new GenericThing<t>
I get a warning saying type or namespace expected. What am i missing?
t
is a Type object created at runtime. Generics expect a type name, resolved at compile time. To create a generic at runtime, you have to use MakeGenericType
For example:
Activator.CreateInstance(typeof(GenericThing<>).MakeGenericType(t));
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