what is the valid argument for IEnumerator on TreeNode?
i got the error on this line:
IEnumerator ie = tn.Nodes.GetEnumerator();
in this method:
private void parseNode(TreeNode tn)
{
IEnumerator ie = tn.Nodes.GetEnumerator();
string parentnode = "";
parentnode = tn.Text;
while (ie.MoveNext())
{
TreeNode ctn = (TreeNode)ie.Current;
if (ctn.GetNodeCount(true) == 0)
{
_nodeToString += ctn.Text;
}
else
{
_nodeToString += "<" + ctn.Text + ">";
}
if (ctn.GetNodeCount(true) > 0)
{
parseNode(ctn);
}
}
_nodeToString += "</" + parentnode + ">";
_nodeToString += "\n";
}
(from comments)
That means you have
and not
switch to the latter and it will work.
IEnumerable/IEnumeratorare the non-generic API.Or better: use
foreach– it is simpler, safer and more correct (you didn’t remember to check forIDisposable, for example).Additional notes:
StringBuilderis preferred by a long marginXmlWriterwould be idealso IMO: use an
XmlWriterthat writes to aStringBuilder, usingforeachUntested, but something like: