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;
}