Пример #1
0
        private void WriteEntry(System.Xml.XmlWriter writer, ReflectedMember entryMember, string displayName, string type)
        {
            CRefPath       currentPath    = CRefPath.Create(entryMember);
            XmlCodeComment currentComment = this._xmlComments.GetComment(currentPath);

            writer.WriteStartElement("entry");
            writer.WriteAttributeString("id", entryMember.GetGloballyUniqueId().ToString());
            writer.WriteAttributeString("subId", string.Empty);
            writer.WriteAttributeString("type", type);
            writer.WriteAttributeString("visibility", ReflectionHelper.GetVisibility(entryMember));
            writer.WriteAttributeString("cref", currentPath.ToString());

            writer.WriteStartElement("name");
            writer.WriteString(displayName);
            writer.WriteEndElement();

            // find and output the summary
            if (currentComment != XmlCodeComment.Empty && currentComment.Elements != null)
            {
                XmlCodeElement summary = currentComment.Elements.Find(currentBlock => currentBlock is SummaryXmlCodeElement);
                if (summary != null)
                {
                    Serialize(summary, writer);
                }
            }
            writer.WriteEndElement();
        }
Пример #2
0
        private void BuildMethodEntries(string collectionName, List <MethodDef> entries, Entry typeEntry, ICommentSource commentsXml)
        {
            if (entries.Count == 0)
            {
                return;
            }

            ReflectedMember containingType = (ReflectedMember)typeEntry.Item;

            Entry eventsEntry = EntryCreator.Create(entries, collectionName, commentsXml, typeEntry);

            eventsEntry.IsSearchable = false;
            eventsEntry.Key          = containingType.GetGloballyUniqueId();
            eventsEntry.SubKey       = collectionName;

            foreach (MethodDef current in entries)
            {
                PreEntryAddedEventArgs e = new PreEntryAddedEventArgs(current);
                this.OnPreEntryAdded(e);
                if (!e.Filter)
                {
                    Entry propertyEntry = EntryCreator.Create(current, current.GetDisplayName(false, false), commentsXml, eventsEntry);
                    propertyEntry.IsSearchable = true;
                    propertyEntry.Key          = current.GetGloballyUniqueId();
                    eventsEntry.Children.Add(propertyEntry);
                }
            }

            if (eventsEntry.Children.Count > 0)
            {
                eventsEntry.Children.Sort();
                typeEntry.Children.Add(eventsEntry);
            }
        }
Пример #3
0
        /// <summary>
        /// Renders a seealso xml block when the specified member has seealso references in the comments.
        /// </summary>
        /// <param name="member">The member to render the block for.</param>
        /// <param name="writer">The writer to write the xml to.</param>
        /// <param name="comment">The associated xml comments.</param>
        protected void RenderSeeAlsoBlock(ReflectedMember member, System.Xml.XmlWriter writer, XmlCodeComment comment)
        {
            if (comment != XmlCodeComment.Empty)
            {
                List <XmlCodeElement> elements = comment.Elements.FindAll(e => e.Element == XmlCodeElements.SeeAlso);
                if (elements != null && elements.Count > 0)
                {
                    writer.WriteStartElement("seealsolist");
                    foreach (SeeAlsoXmlCodeElement current in elements)
                    {
                        string displayName = current.Member.TypeName;
                        Entry  entry       = this.Document.Find(current.Member);

                        writer.WriteStartElement("seealso");
                        if (entry != null)
                        {
                            displayName = entry.Name;
                            ReflectedMember foundMember = entry.Item as ReflectedMember;
                            if (foundMember != null)
                            {
                                writer.WriteAttributeString("id", foundMember.GetGloballyUniqueId().ToString());
                                this.WriteCref(entry, writer);
                            }
                        }
                        writer.WriteString(displayName);
                        writer.WriteEndElement(); // seealso
                    }
                    writer.WriteEndElement();     // seealsolist
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Renders the list of defined exceptions for the specified <paramref name="member"/>.
        /// </summary>
        /// <param name="member">The member to render the exceptions for.</param>
        /// <param name="writer">The writer to write the exceptions to.</param>
        /// <param name="comment">The XmlCodeComment to read the exceptions from.</param>
        protected virtual void RenderExceptionBlock(ReflectedMember member, System.Xml.XmlWriter writer, XmlCodeComment comment)
        {
            // output documentation for expected exceptions if they are defined
            if (comment != XmlCodeComment.Empty)
            {
                List <XmlCodeElement> exceptions = comment.Elements.FindAll(node => node is ExceptionXmlCodeElement);
                if (exceptions != null && exceptions.Count > 0)
                {
                    writer.WriteStartElement("exceptions");
                    for (int i = 0; i < exceptions.Count; i++)
                    {
                        ExceptionXmlCodeElement current = (ExceptionXmlCodeElement)exceptions[i];
                        string          exceptionName   = string.Empty;
                        ReflectedMember found           = null;

                        if (current.Member.PathType != CRefTypes.Error)
                        {
                            TypeDef def = member.Assembly.FindType(current.Member.Namespace, current.Member.TypeName);
                            exceptionName = string.Format("{0}.{1}", current.Member.Namespace, current.Member.TypeName);

                            if (def != null)
                            {
                                found = def;
                                switch (current.Member.PathType)
                                {
                                // these elements are named and the type of element will
                                // not modify how it should be displayed
                                case CRefTypes.Field:
                                case CRefTypes.Property:
                                case CRefTypes.Event:
                                case CRefTypes.Namespace:
                                    break;

                                // these could be generic and so will need to modify to
                                // a more appropriate display name
                                case CRefTypes.Method:
                                    MethodDef method = current.Member.FindIn(def) as MethodDef;
                                    if (method != null)
                                    {
                                        found         = method;
                                        exceptionName = method.GetDisplayName(false);
                                    }
                                    break;

                                case CRefTypes.Type:
                                    exceptionName = def.GetDisplayName(false);
                                    break;
                                }
                            }
                        }

                        writer.WriteStartElement("exception");
                        writer.WriteStartElement("name");
                        if (found != null)
                        {
                            writer.WriteAttributeString("key", found.GetGloballyUniqueId().ToString());
                            writer.WriteAttributeString("cref", current.Member.ToString());
                        }
                        writer.WriteString(exceptionName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("condition");
                        for (int j = 0; j < current.Elements.Count; j++)
                        {
                            this.Serialize(current.Elements[j], writer);
                        }
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }
Пример #5
0
        /// <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);
        }