最近我用了DLL写的一个类,如下:
public class Class1
{
public delegate int SerchQZPara(int mainParaNo, int subParaNo, ref double var);
public SerchQZPara readQZPara;
}
在主form程序中利用反射加载DLL时想给此属性赋值,我已经作过如下试验,
obj = Activator.CreateInstance(type);
m = type.GetMethod("SendMeasueResults");
fimfo=type.GetField("readQZPara");
fimfo.SetValue(obj,readQZPara);
但是报出如下异常
“Object of type 'TestReflection.Form1+SerchQZPara' cannot be converted to type 'DLL.Class1+SerchQZPara'“.
请问各高手是否能指点,或者说在c#中是这种方式是否可行。
public class Class1
{
public delegate int SerchQZPara(int mainParaNo, int subParaNo, ref double var);
public SerchQZPara readQZPara;
}
在主form程序中利用反射加载DLL时想给此属性赋值,我已经作过如下试验,
obj = Activator.CreateInstance(type);
m = type.GetMethod("SendMeasueResults");
fimfo=type.GetField("readQZPara");
fimfo.SetValue(obj,readQZPara);
但是报出如下异常
“Object of type 'TestReflection.Form1+SerchQZPara' cannot be converted to type 'DLL.Class1+SerchQZPara'“.
请问各高手是否能指点,或者说在c#中是这种方式是否可行。
//定义为静态
fimfo.SetValue(obj,new Class1.SerchQZPara(readQZPara));
这样如何?