public void RemoveAllInputPortsFromNode(List <string> without = null) { if (without == null) { while (InputPorts.Any()) { RemoveInputPortFromNode(InputPorts.First()); } } else { var filteredPorts = InputPorts.Where(port => !without.Contains(port.Name)).ToList(); foreach (var port in filteredPorts) { RemoveInputPortFromNode(port); } } }
/// <summary> /// 获取IO口 /// </summary> /// <typeparam name="T">Inputport或者OutputPort</typeparam> /// <param name="condition">IO口的no或者name</param> /// <returns>满足条件的Inputport或者OutputPort</returns> public T GetPort <T>(object condition) { object[] arrayObj = null; //先判断查找的是输入端口还是输出端口 if (typeof(T) == typeof(OutputPort)) { if (condition is int) { arrayObj = (object[])(OutputPorts.Where(x => x.bitno == (int)condition)); } else if (condition is string) { arrayObj = (object[])(OutputPorts.Where(x => x.name == (string)condition)); } //不满足条件 arrayObj还是为null } else if (typeof(T) == typeof(InputPort)) { if (condition is int) { arrayObj = InputPorts.Where(x => x.bitno == (int)condition).ToArray(); } else if (condition is string) { arrayObj = InputPorts.Where(x => x.name == (string)condition).ToArray(); } //不满足条件 arrayObj还是为null } if (arrayObj == null || arrayObj.Length == 0) //输入的T不符合要求arrayObj为null,condition没找到arrayObj长度为0,两种都是不满足要求 { return(default(T)); } if (arrayObj.Length > 1) { throw new Exception("Two or more ports was set to be port \"" + condition.ToString() + " !!!"); } return((T)arrayObj[0]); }