static ConditionSet ExportConditions(GroupNode node) { ConditionSet set; switch (node.Op) { case GroupNodeType.AND: set = new ConditionAND(); break; case GroupNodeType.OR: set = new ConditionOR(); break; case GroupNodeType.NAND: set = new ConditionNAND(); break; case GroupNodeType.NOR: set = new ConditionNOR(); break; default: throw new ArgumentOutOfRangeException(); } foreach (TreeNode subNode in node.Nodes) { if (subNode is GroupNode) { set.Add(ExportConditions((GroupNode)subNode)); } else if (subNode is ConditionNode) { ConditionNode sn = (ConditionNode)subNode; ConditionIntRange cond = new ConditionIntRange { Comparison = sn.Op, Field = sn.Field, Value = sn.Value }; set.Add(cond); } else { throw new Exception(); } } return(set); }
static void ImportCondition(GroupNode parent, Condition condition) { if (condition is ConditionIntRange) { ConditionIntRange cond = (ConditionIntRange)condition; ConditionNode newNode = new ConditionNode { Field = cond.Field, Value = cond.Value, Op = cond.Comparison }; parent.Nodes.Add(newNode); } else if (condition is ConditionSet) { ConditionSet set = (ConditionSet)condition; GroupNode newNode = new GroupNode(); if (set is ConditionAND) { newNode.Op = GroupNodeType.AND; } else if (set is ConditionOR) { newNode.Op = GroupNodeType.OR; } else if (set is ConditionNAND) { newNode.Op = GroupNodeType.NAND; } else if (set is ConditionNOR) { newNode.Op = GroupNodeType.OR; } else { return; } foreach (Condition subCondition in set.Conditions) { ImportCondition(newNode, subCondition); } parent.Nodes.Add(newNode); } }