Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

JvCoach23

VB.Net newbie

MS Sql Vet

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...