public static SetNode Unite(SetNode A, SetNode B) { if (A.Type == SetNode.NodeType.OPERATOR || B.Type == SetNode.NodeType.OPERATOR) { return(A & B); } var newSet = new Set(); foreach (var piece in A as Set) { newSet.AddPiece(piece); } foreach (var piece in B as Set) { newSet.AddPiece(piece); } return(newSet); }