public static TreeNode AddForEachNode(this TreeNode parent, Func<TreeNodeTag, object> valuesToAdd, Func<object, string> toStringFunc, TreeNodeType type)
{
foreach (TreeNode node in parent.Nodes)
{
object rawValue = valuesToAdd((TreeNodeTag)node.Tag);
if (rawValue == null)
continue;
if (rawValue is Array)
node.AddSubNodes((object[])rawValue, toStringFunc).MakeOtherType((o) => { return true; } , type);
else
node.AddSubNodes(new object[] { rawValue }, toStringFunc).MakeOtherType((o) => { return true; }, type);
}
return parent;
}