Creating a generic object based on a Type variable [duplicate]

Type type = typeof(MyObject<>).MakeGenericType(objectType);
object myObject = Activator.CreateInstance(type);

Also – watch out; Type.GetType(string) only checks the executing assembly and a few system assemblies; it doesn’t scan everything. If you use an assembly-qualified-name you should be fine – otherwise you may need to get the Assembly first, and use someAssembly.GetType(string).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)