An C # example of something pretty close is located here on a question I had:
typeof(MyClass).GetMethod("Foo").MakeGenericMethod(new[] { param.GetType() }).Invoke(null, new[] { param });
Converting to VB.NET, changing it to create a type without calling a method and using your names for you:
Dim frmExample as LookupForm<Models.MyClass>; Dim SelectedType as Type = InstanceOfMyClass.GetType(); Dim GenericLookupType as Type = GetType(LookupForm(Of)).MakeGenericType(SelectedType) frmExample = Activator.CreateInstance(GenericLookupType, new object(){})
(Ah for some reason I thought you wanted it in VB.NET, but here is an example of C #)
LookupForm<Models.MyClass> frmExample; Type SelectedType = InstanceOfMyClass.GetType(); Type GenericLookupType = typeof(LookupForm<>).MakeGenericType(SelectedType); frmExample = Activator.CreateInstance(GenericLookupType, new object[]{});
source share