SyntaxTreeNodeCollection GetModifiedSubNodes(SyntaxTreeNode node) { SyntaxTreeNodeCollection modifiedSubNodes = null; //lazy for (int i = 0; i < node.SubNodes.Count; i++) { var subNode = node.SubNodes[i]; var replacement = Visit(subNode); if (replacement != subNode) { if (modifiedSubNodes == null) //lazy init { modifiedSubNodes = new SyntaxTreeNodeCollection(); for (int j = 0; j < i; j++) //copy unmodified nodes { modifiedSubNodes.Add(node.SubNodes[j]); } } if (replacement != null) //insert replacement { modifiedSubNodes.Add(replacement); } } else { if (modifiedSubNodes != null) //only insert unmodified subnode if the lazy collection has been initialized { modifiedSubNodes.Add(subNode); } } } return(modifiedSubNodes); }
SyntaxTreeNodeCollection GetModifiedSubNodes(SyntaxTreeNode node) { SyntaxTreeNodeCollection modifiedSubNodes = null; //lazy for (int i = 0; i < node.SubNodes.Count; i++) { var subNode = node.SubNodes[i]; var replacement = Visit(subNode); if (replacement != subNode) { if (modifiedSubNodes == null) //lazy init { modifiedSubNodes = new SyntaxTreeNodeCollection(); for (int j = 0; j < i; j++) //copy unmodified nodes modifiedSubNodes.Add(node.SubNodes[j]); } if (replacement != null) //insert replacement modifiedSubNodes.Add(replacement); } else { if (modifiedSubNodes != null) //only insert unmodified subnode if the lazy collection has been initialized modifiedSubNodes.Add(subNode); } } return modifiedSubNodes; }
public SequenceNode(SyntaxTreeNodeCollection subNodes) : base(subNodes) { if (subNodes == null) throw new ArgumentNullException("subNodes"); }