Hi. I have a class called NTree:
class NTree<T>
{
delegate bool TreeVisitor<T>(T nodeData);
public NTree(T data)
{
this.data = data;
children = new List<NTree<T>>();
_stopTraverse = false;
}
...
public void Traverse(NTree<T> node, TreeVisitor<T> visitor)
{
try
{
_stopTraverse = false;
TraverseInternal(node, visitor);
}
finally
{
_stopTraverse = false;
}
}
private void TraverseInternal(NTree<T> node, TreeVisitor<T> visitor)
{
if (_stopTraverse)
return;
if (!visitor(node.data))
{
_stopTraverse = true;
}
foreach (NTree<T> kid in node.children)
TraverseInternal(kid, visitor);
}
When I try to use Traverse with anonymous delegate I get:
Argument '2': cannot convert from 'anonymous method' to 'NisConverter.TreeVisitor'
The code:
tTable srcTable = new tTable();
DataRow[] rows;
rootTree.Traverse(rootTree, delegate(TableRows tr)
{
if (tr.TableName == srcTable.mappingname)
{
rows = tr.Rows;
return false;
}
});
This however produces no errors:
static bool TableFinder<TableRows>(TableRows tr)
{
return true;
}
...
rootTree.Traverse(rootTree, TableFinder);
I have tried to put "arrowhead-parenthisis" and everything to anonymous delegate but it just does not work. Please help me!
Thanks & BR -Matti