出于某种原因,当我尝试扩展_nodeDependencies
列表中的每个项目时IEnumerable<Node<T>>
,它显示有 13 个项目,但是当我开始扩展它们时,它说它无法向我显示内容,并且在我点击后调试器最终退出许多 + 以展开列表中的项目。我不知道这是泛型在运行时的工作方式还是什么。
public class Tree<T> where T : INode
{
private readonly IEnumerable<T> _sourceDependencies;
private IEnumerable<Node<T>> _nodeDependencies;
public Node<T> RootNode { get; set; }
public Dictionary<Node<T>, IList<Node<T>>> FlattenedMap { get; private set; }
public Tree(T rootNode, IEnumerable<T> dependencies)
{
RootNode = new Node<T>(rootNode);
_sourceDependencies = dependencies;
}
public void BuildTree()
{
_nodeDependencies = ConvertDependenciesToNodes(_sourceDependencies);
AddChildren();
}
private IEnumerable<Node<T>> ConvertDependenciesToNodes(IEnumerable<T> listToConvert)
{
IEnumerable<Node<T>> nodeList = listToConvert.Select(sourceNode => new Node<T>(sourceNode)).ToList();
return nodeList;
}
}
当我将鼠标悬停时,意义重大_nodeDependencies = ConvertDependenciesToNodes(_sourceDependencies);
_nodeDependencies
说 13 项,所以我展开列表,然后尝试展开一项或两项,它对我保释并停止调试