I am making a windows forms application. I am using a TreeView to display the Namespaces.
var namespaces = assembly.GetTypes()
.ToLookup(ns => ns.Namespace);
foreach (var subNamespace in namespaces)
{
TreeNode assemblyNode = multiSelectMethodTree.Nodes
.Add(subNamespace.Key);
}
Since there is a huge number of Methods and Classes in the project, I thought of displaying the classes only when the user clicks to expand(‘+’) a namespace, and display methods when a class is expanded.
private void MultiSelectMethodTree_AfterExpand(object sender, TreeViewEventArgs e)
{
TreeNode expandedNode = e.Node;
}
In the AfterExpand event, I am not able to identify whether it is a namespace or a class.
You could inherit from
TreeNodeclass to create specific types each for Namespace, Class, Enum etc.Example:
And instead of creating
TreeNodeobject, create an object of these types.To identify which node is selected, you can do following: