コード例 #1
0
 public void ConnectPeripheral(Peripheral peripheral)
 {
     if (Connectors == null || Connectors.GetType() != t)
     {
         throw new Exception("No available connectors of the connection-type of the peripheral!");
     }
     else
     {
         Peripherals.Add(peripheral);
     }
 }
コード例 #2
0
        // A “DisconnectPeripheral()” method that accepts a type of peripheral,
        //and will disconnect all connected peripherals of that type.


        //For the “RemovePeripheral()” method, you could try using a Where() with a clause
        //checking for type not equal to the type to remove
        //(see Sept03Practice commit “SpaceCovered and LinesDrawn;”, Drawing.cs).

        public void DisconnectPeripheral(Peripheral peripheral)
        {
            if (Peripherals != null)
            {
                var toRemove = Peripherals.Where(x => typeof(Connector) == typeof(Connector)).ToList();

                foreach (var item in toRemove)
                {
                    Peripherals.Remove(item);
                }
            }
        }