internal PresentableFactTree(XbrlSchema schema, FactCollection facts) { TopLevelNodes = new List <PresentableFactTreeNode>(); var presentationLinkbase = schema.PresentationLinkbase; foreach (var presentationLink in presentationLinkbase.PresentationLinks) { var unorderedPresentationArcs = presentationLink.PresentationArcs; var orderedPresentationArcs = unorderedPresentationArcs.OrderBy(o => o.Order).ToList(); var newTreeNode = new PresentableFactTreeNode(); TopLevelNodes.Add(newTreeNode); foreach (var orderedPresentationArc in orderedPresentationArcs) { // Set the tree node's node fact, if it is not already set. // // This code is making an assumption that each arc in the link is set up with // the same "from" locator, so locating the "from" fact only needs to be done // if it is not already set. If it is already set, the code assumes that it // was set from a previous arc and doesn't not need to be set again (presumably // with the same information it would get this time if it did all of the work // again). // // If the locator references an abstract element, then there will be no fact // and the value will remain null. if (newTreeNode.NodeFact == null) { var fromLocator = GetLocator(orderedPresentationArc.From, presentationLink); newTreeNode.PresentationLinkbaseLocator = fromLocator; newTreeNode.NodeLabel = GetLabel(schema, fromLocator); var fromElement = GetElement(schema, fromLocator.HrefResourceId); if (fromElement.IsAbstract == false) { var fromFact = facts.GetFactByName(fromElement.Name); newTreeNode.NodeFact = fromFact; } } var toLocator = GetLocator(orderedPresentationArc.To, presentationLink); var newChildTreeNode = new PresentableFactTreeNode(); newTreeNode.ChildNodes.Add(newChildTreeNode); newTreeNode.NodeLabel = GetLabel(schema, toLocator); newChildTreeNode.PresentationLinkbaseLocator = toLocator; var toElement = GetElement(schema, toLocator.HrefResourceId); if (toElement.IsAbstract == false) { var toFact = facts.GetFactByName(toElement.Name); newChildTreeNode.NodeFact = toFact; } } } }