需要被反射调用类代码片段如下:namespace Cj.Tk.Form
{
public partial class Form_ZZS : Cj.Common.Forms.InvForm
{
internal Form_ZZS(LX lx, string bm, string mc)
{
........
}
......
}
}我想要反射调用这个类,但是他的构造函数是internal类型的,我使用了下面的方法,不行,报错内容是找不到构造函数
Type t2 = testAssembly.GetType("Cj.Tk.Form.Form_ZZS");
object cm2 = Activator.CreateInstance(t2, new object[] { LX.ZY, GetCurrent[0], GetCurrent[1] });使用下面的方法仍然报错,直接进入else分支中Type[] types = new Type[3];
types[0] = typeof(LX);
types[1] = typeof(string);
types[2] = typeof(string);
ConstructorInfo constructorInfoObj = t2.GetConstructor(types);
if (constructorInfoObj != null)
{
MessageBox.Show(constructorInfoObj.ToString());
}
else
{
MessageBox.Show("The constructor of MyClass1 that takes an integer " +
"as a parameter is not available.");
}请教各位高手该如何处理呢?
C# 反射 internal构造函数
{
public partial class Form_ZZS : Cj.Common.Forms.InvForm
{
internal Form_ZZS(LX lx, string bm, string mc)
{
........
}
......
}
}我想要反射调用这个类,但是他的构造函数是internal类型的,我使用了下面的方法,不行,报错内容是找不到构造函数
Type t2 = testAssembly.GetType("Cj.Tk.Form.Form_ZZS");
object cm2 = Activator.CreateInstance(t2, new object[] { LX.ZY, GetCurrent[0], GetCurrent[1] });使用下面的方法仍然报错,直接进入else分支中Type[] types = new Type[3];
types[0] = typeof(LX);
types[1] = typeof(string);
types[2] = typeof(string);
ConstructorInfo constructorInfoObj = t2.GetConstructor(types);
if (constructorInfoObj != null)
{
MessageBox.Show(constructorInfoObj.ToString());
}
else
{
MessageBox.Show("The constructor of MyClass1 that takes an integer " +
"as a parameter is not available.");
}请教各位高手该如何处理呢?
C# 反射 internal构造函数
你把你现在的命名空间也搞成namespace Cj.Tk.Form
其实一楼的回答没错,不管是方法还是构造函数
道理都是一样的