public void ReplaceConnection(Connection replace, Output replaceWith) { if (replace.Condition == null) { if (Con != replace.From) { throw new Exception("Input is not connected to the given output."); } replace.From.DisconnectOnlyOutputSide(this); replaceWith.ConnectOnlyOutputSide(this); Con = replaceWith; } else { if (CondCons != null) { for (int i = 0; i < CondCons.Count; i++) { if (CondCons[i] == replace) { replace.From.DisconnectOnlyOutputSide(this); replaceWith.ConnectOnlyOutputSide(this); CondCons[i] = new Connection(replaceWith, replace.Condition); return; } } } throw new Exception("Input is not conditionally connected to the given output."); } }