/// <summary>
        /// Retrieves the XmlDocument for the provided <paramref name="crefPath"/>.
        /// </summary>
        /// <param name="crefPath">The CRefPath to retrieve the documentation for.</param>
        /// <include file='Documentation\documentation.xml' path='members/member[@name="GetDocumentationFor.cref"]/*'/>
        public string GetDocumentationFor(string crefPath)
        {
            if (string.IsNullOrEmpty(crefPath))
            {
                throw new ArgumentNullException("crefPath");
            }
            if (!_isLoaded)
            {
                throw new InvalidOperationException("The documentation is not loaded, call Load first");
            }

            Reflection.Comments.CRefPath path = Reflection.Comments.CRefPath.Parse(crefPath);
            if (path.PathType == Reflection.Comments.CRefTypes.Error)
            {
                throw new DocumentationException("The provided cref path {0} did not parse correctly.");
            }

            Entry entry = _baseDocument.Find(path);

            if (entry == null)
            {
                throw new EntryNotFoundException("The provided path {0} did not resolve to a member.");
            }

            return(GetDocumentationFor(entry));
        }
        /// <summary>
        /// Retrieves the ContentEntry for the provided <paramref name="crefPath"/>.
        /// </summary>
        /// <param name="crefPath">The CRefPath to retrieve the documentation for.</param>
        /// <returns>The ContentEntry for the specified crefpath or null if not found.</returns>
        /// <include file='Documentation\tableofcontents.xml' path='members/member[@name="GetEntryFor.cref"]/*'/>
        public ContentEntry GetEntryFor(string crefPath)
        {
            Reflection.Comments.CRefPath path = Reflection.Comments.CRefPath.Parse(crefPath);
            if (path.PathType == Reflection.Comments.CRefTypes.Error)
            {
                throw new DocumentationException("The provided cref path {0} did not parse correctly.");
            }

            Entry found = _document.Find(path);

            return(found == null ? null : new ContentEntry(_document.Find(path)));
        }
Exemple #3
0
            /// <summary>
            /// Finds the <paramref name="entry"/> in the new DocumentMap.
            /// </summary>
            /// <param name="entry"></param>
            /// <returns></returns>
            private Entry Find(Entry entry)
            {
                Entry found = null;

                if (entry != null)
                { // only if something was previously selected
                    Entry parent = entry.Parent;

                    if (entry.Item is Reflection.ReflectedMember)
                    {
                        Reflection.Comments.CRefPath path = Reflection.Comments.CRefPath.Create(
                            entry.Item as Reflection.ReflectedMember
                            );
                        found = LiveDocumentorFile.Singleton.LiveDocument.Find(path);
                    }
                    else if (parent != null && parent.Item is Reflection.ReflectedMember)
                    {
                        Reflection.Comments.CRefPath path = Reflection.Comments.CRefPath.Create(
                            parent.Item as Reflection.ReflectedMember
                            );
                        found = LiveDocumentorFile.Singleton.LiveDocument.Find(path);

                        // test method/field member collection pages in a type
                        for (int i = 0; i < found.Children.Count; i++)
                        {
                            if (found.Children[i].Name == entry.Name)
                            {
                                found = found.Children[i];
                                break;
                            }
                        }
                    }
                    else
                    {
                        // now its a namespace or namespace collection page and we will ignore
                        // it for now
                        bool isNamespaceContainer = entry.Item is EntryTypes &&
                                                    ((EntryTypes)entry.Item) == EntryTypes.NamespaceContainer;
                        List <Entry> childrenToSearch = new List <Entry>();

                        // get children that can be searched for
                        if (isNamespaceContainer)
                        {
                            for (int i = 0; i < entry.Children.Count; i++)
                            {
                                childrenToSearch.AddRange(entry.Children[i].Children);
                            }
                        }
                        else
                        {
                            childrenToSearch.AddRange(entry.Children);
                        }

                        // iterate over each item until one is found
                        Entry foundChildItem = null;
                        for (int i = 0; i < childrenToSearch.Count; i++)
                        {
                            Reflection.ReflectedMember item = childrenToSearch[i].Item as Reflection.ReflectedMember;
                            if (item != null)
                            {
                                Reflection.Comments.CRefPath path = Reflection.Comments.CRefPath.Create(item);
                                foundChildItem = LiveDocumentorFile.Singleton.LiveDocument.Find(path);
                                break;
                            }
                        }

                        if (foundChildItem != null)
                        {
                            if (isNamespaceContainer)
                            {
                                foundChildItem.Parent.Parent.IsExpanded = entry.IsExpanded;
                            }
                            else
                            {
                                foundChildItem.Parent.IsExpanded = entry.IsExpanded;
                            }
                        }
                    }
                }

                return(found);
            }