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.
NullableDataReader dr = cmFrom.Data_Reader;
object[] argumentItems = { dr };
string loc = "Common." + "NullableDataReader" + ", " + _AssemblyName + ",
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type drType = Type.GetType(loc);
Type[] parms = { drType };
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" and the "drType" in the debugger, it shows
me an appropriate value. The "dr" has an appropriate reference to the
"NullableDataReader".
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.
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.
NullableDataReader dr = cmFrom.Data_Reader;
object[] argumentItems = { dr };
string loc = "Common." + "NullableDataReader" + ", " + _AssemblyName + ",
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type drType = Type.GetType(loc);
Type[] parms = { drType };
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" and the "drType" in the debugger, it shows
me an appropriate value. The "dr" has an appropriate reference to the
"NullableDataReader".
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.
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!!