In Visual Basic.net, can I create an Object, or a List of T with the type from another object.
Here is some code:
Dim TestObjectType As Author
Dim TestObject As TestObjectType.GetType
I am getting an error:
TestObjectType.GetType is not defined
EDIT
Can I create a Type object of a certain type, and then create objects, lists or cast objects to this type from this Type object?
Dim TestObject As TestObjectType.GetType
will look for a type namedGetType
in the namespaceTestObjectType
.To create an instance of a class using
System.Type
, you can useActivator.CreateInstance
:To create a generic list, you can use
Type.MakeGenericType
:Note that both snippets above return an
Object
; however, you can make use of generics to achieve compile time safety: