private void SetSendDelegate(ComBase com, ComDataEventHandler callback) { FieldInfo field = null; var fs = typeof(ComBase).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); //Linq var x = from f in fs where f.Name == "_sendToConnector" select f; field = x.First(); field.SetValue(com, callback); }
public void Close() { if (com1 != null) { ConnectorToComBase(com1, null); SetSendDelegate(com1, null); ConnectorToComBase(com2, null); SetSendDelegate(com2, null); com1 = null; com2 = null; } }
/// <summary> /// 通过反射设置com._connector = connector; /// </summary> private void ConnectorToComBase(ComBase com, ComConnector connector) { FieldInfo field = null; var fs = typeof(ComBase).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); //Linq var x = from f in fs where f.Name == "_connector" select f; field = x.First(); field.SetValue(com, connector); }
public void Bind(ComBase com1, ComBase com2) { if (com1 == null) { return; } this.com1 = com1; this.com2 = com2; ConnectorToComBase(com1, this); SetSendDelegate(com1, com2.OnDataReceive); ConnectorToComBase(com2, this); SetSendDelegate(com2, com1.OnDataReceive); }
public WLCom() { comBase = new WLComport(this); }