Here's Why
it actualy makes no sense to want to do that... if you want to send it through a method, want to use its methods or anything else then you know the type and can cast it. However, if you do not know the type, what could you do with it?
Welll, I didn't need to pass in a String for the Type Name like the O.P., but I needed to pass in a Type to avoid separate Function / internal Select Case per Type.
''' If Source Value Object (SrceValObj) is not System.DBNull.Value, assign it to Target Value Object
''' (TargValObj) and return True, else return False. If a Target Type (TargType) is specified, perform
''' a Dynamic Type Conversion to that Type first.
Public Shared Function AsgnToTypeIfNotDBNull(
ByVal SrceValObj As Object,
ByRef TargValObj As Object,
Optional ByVal TargType As Type = Nothing
) As Boolean
This Function avoided an If Statement per Column being loaded from a Database and performed necessary dynamic conversions (like from Decimal (within Integer range) to Integer) using the CTypeDynamic Function suggested by the O.P.
Whenever you want to do this, you should simply cast it to Object... There is no actual way of telling the compiler you want a "runtime determined type" reference. That would break the whole strong typing model...
Well maybe not completely, but I did need to create an Instance of a Class specified at runtime (via a DB Table (for a DB Table - Driven menu of U.I. Forms). They did need to inherit from a common Base Class (i.e. Form or MyAppBaseForm) which is all my menu cared about, but the Instances could be Type-Casted to the actual derived Form (i.e. from within one Form trying to access another Form).
''' Create and return an Instance of a Form giving its Class Name (FormClsNameStr). If
''' FormClsNameStr doesn't exist, show an error and return Nothing.
Public Function CreateFrmInstance( _
ByVal FormClsNameStr As String _
) As Form
This Function used My.Application.Info.AssemblyName, Type.GetType and System.Activator.CreateInstance.