示例#1
0
        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);
        }
示例#2
0
        public void Close()
        {
            if (com1 != null)
            {
                ConnectorToComBase(com1, null);
                SetSendDelegate(com1, null);
                ConnectorToComBase(com2, null);
                SetSendDelegate(com2, null);

                com1 = null;
                com2 = null;
            }
        }
示例#3
0
        /// <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);
        }
示例#4
0
        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);
        }
示例#5
0
 public WLCom()
 {
     comBase = new WLComport(this);
 }