/// <summary> /// Searches the Document for the entry related to the specified <paramref name="path"/>. /// </summary> /// <param name="path">The CRefPath to search for.</param> /// <returns>The Entry if it is found else null.</returns> public Entry Find(CRefPath path) { if (path == null || path.PathType == CRefTypes.Error) { return(null); } if (Map.Count == 0) { return(null); } // find the level of the namespace entries int level = 1; Entry found = Map[0]; while (!(found.Item is KeyValuePair <string, List <TypeDef> >)) { found = found.Children[0]; level++; } found = null; List <Entry> namespaceEntries = new List <Entry>(); // flattend list of namespaces if (level == 1) { namespaceEntries.AddRange(Map); } else { for (int i = 0; i < Map.Count; i++) { namespaceEntries.AddRange(GetAllEntriesFromLevel(level, 2, Map[i])); } } for (int i = 0; i < namespaceEntries.Count; i++) { Entry currentLevel = namespaceEntries[i]; if (string.Compare(currentLevel.SubKey, path.Namespace, true) == 0) { // if we are searching for a namespace, we are done now as we have found it if (path.PathType == CRefTypes.Namespace) { found = currentLevel; break; } // search the types in the namespace for (int j = 0; j < currentLevel.Children.Count; j++) { Entry currentTypeEntry = currentLevel.Children[j]; TypeDef currentType = (TypeDef)currentTypeEntry.Item; if (string.Compare(currentType.Name, path.TypeName, true) == 0) { // if we are searchinf for a type, we are done now if (path.PathType == CRefTypes.Type) { found = currentTypeEntry; break; } // find the type and do the quick type search to find the related // entry. this is the quickest way. ReflectedMember member = path.FindIn(currentType); if (member != null) { // someone could have misspelled the member in the crefpath found = currentTypeEntry.FindByKey(member.GetGloballyUniqueId(), string.Empty); break; } } } } if (found != null) { break; } } return(found); }