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!!
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!!