late binding question

jvcoach23

Centurion
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
i do early binding for everything so far. I now have a need to do latebinding (i think).

I'm have a log file that i use to record changes made in a vb app. It uses reflection (think that the right term) where i pass in an object and it takes the object and creates a single string out of the properties

in that table, there is a column where i store the object name. Now i'd like to take that object name and query against it using my class structure.

So, say i have a class named ClassIndex with property names like tblClassIndexID, ClassName, ClassTitle

if i query my table and bring back a certain row, i look and see that the class name was ClassIndex. in early binding i'd do

dim oClassIndex as new ClassIndex

how do i do this using late binding.
hope that is clear enough
thanks
shannon
 
First you need to get the System.Type object that represents the class' type. Then you can either use the Activator class to create objects, or you can use reflection on the System.Type object to get a constructor (or a MethodInfo object, to be more precise) and call that to create the object (you may also be able to use the InvokeMethod function of the System.Type object).

Note that unless you are dealing with parameterless constructors things are going to get very tricky very fast.
 
Back
Top