我遇到了一些奇怪的事情,我正在使用反射创建一个类的实例,它传递了几个参数,一个是变量:ipAddress,当在构造函数中创建实例时,变量存储在一个字段中,但是一旦构造函数完成,我(在调试器中)返回到创建实例的行,我在类中检查并且字段“ipAddress”已更改为空。这怎么可能?
这是课程的一部分:
public class moxa_nport_5110
{
string instanceName;
Delegate triggerCallBackMethod;
private BPUConsole bpuConsole { get; set; }
TcpIpServer server;
string ipAddress;
public moxa_nport_5110(Delegate TriggerCallBackMethod, Delegate Callback, params object[] CtorParam)
{
#region Initialize
triggerCallBackMethod = TriggerCallBackMethod;
instanceName = (string)CtorParam[0];
string ipAddress = (string)CtorParam[1];
int Port = (int)CtorParam[2];
bpuConsole = new BPUConsole(Callback, instanceName);
#endregion
server = new TcpIpServer("10.100.184.140", 8888, false);
server.OnDataReceived += new TcpIpServer.ReceiveEventHandler(server_OnDataReceived);
server.OnClientConnected += new TcpIpServer.InfoEventHandler(server_OnClientConnected);
server.OnClientDisconnected += new TcpIpServer.InfoEventHandler(server_OnClientDisconnected);
server.OnAbnormalConnectionDisconnect += new TcpIpServer.InfoEventHandler(server_OnAbnormalConnectionDisconnect);
server.AddClient(ipAddress, 1);
}
public void SendData(byte[] Data)
{
server.SendData(ipAddress, Data);
}
这是我创建实例的行:
driverInterface = Activator.CreateInstance(driverType, tempParam); //create an instance of the driver
所以当我返回这里时,字段 ipAddress 的值为空。
编辑:
字段是相同的值,但未访问: