ConstructorInfo

G

Guest

I'm trying to figure out how to use the ConstructorInfo class to get the
appropriate constructor and then use the "Invoke" method to create and
instance of the class. Seems easy enough, but it is not working for me, so
it must be something simple.

Here is the code that I am using, and the last instruction fails.
Type[] parms = { typeof(NullableDataReader) };
Type theTblType = Type.GetType(_TableClassName);
ConstructorInfo methodCreate = theTblType.GetConstructor(parms);
object rec = methodCreate.Invoke(theTblType, argumentItems);
When the last instruction executes, I get a "TargetException" - Object does
not meet the target type.
When I look at the "theTblType", it shows me "{Name = "PS_GL_ACCOUNT_TBL"
FullName = "GL.Table.PS_GL_ACCOUNT_TBL"} and this the class that I am
attempting to create. Below is the constructor for that class, which takes
as an arguement NullableDataReader, which is what I believe I am passing
into the Invoke method.
Here is the constructor of the class that I am trying to create an instance
of..

public PS_GL_ACCOUNT_TBL(NullableDataReader row)

What Am I doing wrong?

Second question, the Invoke method returns an "object", but how can I "cast"
this to a "PS_GL_ACCOUNT_TBL" type when all I have is the text name of that
class?

Thanks in advance for your assistance!!
 
K

Kevin Spencer

You're passing a variable called "argumentItems" to the Invoke method, but
you haven't described what that is.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

I seemed to have missed posting that code, but it is indeed populated. I
have created another post, where I expand the code in the post, but the
results are the same.

Thanks for taking the time to post your comments!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top