示例#1
0
        /// <summary>
        /// Attempts to resolve the provided TypeRef to an EntryKey which can be used to create
        /// a link to the return type.
        /// </summary>
        /// <param name="typeReference">The TypeRef to resolve</param>
        /// <returns>The resolved EntryKey or null if not found.</returns>
        private (EntryKey, string) CreateEntryKey(TypeRef typeReference)
        {
            EntryKey typeKey  = null;
            string   typeName = typeReference.GetDisplayName(false);

            if (typeReference is TypeDef) // TypeDef as it is defined in same library as method
            {
                typeKey = new EntryKey(typeReference.GetGloballyUniqueId());
            }
            else
            {
                // check all other loaded libraries to try and resolve type
                CRefPath            path  = new CRefPath(typeReference);
                Documentation.Entry found = LiveDocumentorFile.Singleton.LiveDocument.Find(path);
                if (found != null)
                {
                    typeKey  = new EntryKey(found.Key);
                    typeName = found.Name;
                }
                else
                {
                    typeKey = null;
                }
            }
            return(typeKey, typeName);
        }
        /// <summary>
        /// Extracts as much information from the state of the exception as possible and returns
        /// it as a formatted string.
        /// </summary>
        /// <returns>The formatted exception details.</returns>
        public string GetExtendedInformation()
        {
            StringBuilder builder = new StringBuilder();

            if (this.Comment != null)
            {
                if (this.Comment == XmlCodeComment.Empty)
                {
                    builder.AppendLine("The associated XmlCodeComment is equal to Empty");
                }
                else
                {
                    if (this.Comment.Member != null)
                    {
                        // get the cref path of the member
                        try
                        {
                            builder.AppendLine($"CRef: {this.Comment.Member.ToString()}");
                        }
                        catch (Exception) { }

                        // if its not null lets just see if we can the base xml for this
                        try
                        {
                            LiveDocumentorFile sf = LiveDocumentorFile.Singleton;
                            if (sf != null && sf.LiveDocument != null)
                            {
                                Documentation.Entry entry = sf.LiveDocument.Find(this.Comment.Member);
                                if (entry != null && entry.XmlCommentFile != null)
                                {
                                    ICommentSource commentSource = entry.XmlCommentFile;
                                    builder.AppendLine(
                                        $"Has XML Comments: {commentSource.Exists()}"
                                        );

                                    builder.AppendLine(
                                        $"XML: {commentSource.GetXml(this.Comment.Member)}"
                                        );
                                }
                            }
                        }
                        catch (Exception) { }
                    }

                    builder.AppendLine("Formatted Comment");
                    this.WriteAsText(builder, this.Comment);
                    builder.AppendLine();
                }
            }
            else
            {
                builder.AppendLine("No XmlCodeComment was stored in the exception");
            }

            return(builder.ToString());
        }
示例#3
0
        /// <summary>
        /// Adds the inheritance tree for the specified <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The type to parse and display the tree for.</param>
        protected void AddInheritanceTree(TypeDef type)
        {
            Func <TypeRef, Inline> createLink = delegate(TypeRef forType)
            {
                string  displayName = forType.GetDisplayName(true); // get a default name to display
                TypeDef typeDef     = forType as TypeDef;
                if (typeDef != null)
                {
                    displayName = typeDef.GetDisplayName(true);
                }

                Hyperlink link = new Hyperlink(new Run(displayName));
                if (typeDef == null)
                {
                    CRefPath            parentCrefPath = new CRefPath(forType);
                    Documentation.Entry found          = LiveDocumentorFile.Singleton.LiveDocument.Find(parentCrefPath);
                    if (found != null)
                    {
                        link.Tag = new EntryKey(found.Key);
                    }
                    else
                    {
                        return(new Run(displayName));
                    }
                }
                else
                {
                    link.Tag = new EntryKey(typeDef.GetGloballyUniqueId());
                }
                link.Click += new System.Windows.RoutedEventHandler(LinkHelper.Resolve);
                return(link);
            };

            // Add the inheritance tree
            Elements.List inheritanceList = new Elements.List();
            Elements.List lastList        = inheritanceList;
            if (type.InheritsFrom != null)
            {
                // build a list of parents for the current type
                TypeRef       parent = type.InheritsFrom;
                List <Inline> links  = new List <Inline>();
                while (parent != null)
                {
                    links.Add(createLink(parent));

                    if (parent is TypeDef)
                    {
                        parent = ((TypeDef)parent).InheritsFrom;
                    }
                    else
                    {
                        parent = null;
                    }
                }

                // Reverse the list and build the inheritance tree
                lastList = inheritanceList;
                for (int i = links.Count - 1; i >= 0; i--)
                {
                    lastList.AddListItem(links[i]);
                    if (i > 0)
                    {
                        lastList = lastList.AddChildList(new Elements.List());
                    }
                }
            }

            // add the current type
            lastList = lastList.AddChildList(new Elements.List());
            lastList.AddListItem(type.GetDisplayName(true));

            // add all the derived types
            lastList = lastList.AddChildList(new Elements.List());
            List <TypeRef> derivedTypes = type.GetExtendingTypes();

            derivedTypes.Sort((a, b) => a.GetFullyQualifiedName().CompareTo(b.GetFullyQualifiedName()));
            for (int i = 0; i < derivedTypes.Count; i++)
            {
                Entry forType = LiveDocumentorFile.Singleton.LiveDocument.Find(
                    CRefPath.Create(derivedTypes[i])
                    );
                if (forType != null)
                {
                    lastList.AddListItem(createLink(derivedTypes[i]));
                }
            }

            this.Blocks.Add(new Header2("Inheritance Hierarchy"));
            this.Blocks.Add(inheritanceList);
        }
示例#4
0
        /// <summary>
        /// Add the parameters section for the provided <paramref name="mathod"/>.
        /// </summary>
        /// <param name="method">The method to add the parameters for.</param>
        /// <param name="parsedBlocks">The parsed comments.</param>
        protected void AddParametersForMethod(MethodDef method, List <Block> parsedBlocks)
        {
            // Add the parameter information if available
            List <Param> parameterComments = Parser.ParseElement <Param>(parsedBlocks);

            if (method.Parameters != null && method.Parameters.Count > 0)
            {
                ParameterList parameters = null;
                foreach (ParamDef methodParam in method.Parameters)
                {
                    if (methodParam.Sequence != 0)
                    {
                        // Find the parameter comments
                        Param paramComment = null;
                        foreach (Param current in parameterComments)
                        {
                            if (current.Name == methodParam.Name)
                            {
                                paramComment = current;
                                break;
                            }
                        }

                        TypeRef  typeRef  = method.ResolveParameter(methodParam.Sequence);
                        EntryKey typeKey  = null;
                        string   typeName = typeRef.Name;
                        if (parameters == null)
                        {
                            parameters = new ParameterList();
                        }
                        if (typeRef != null)
                        {
                            if (typeRef is TypeDef)
                            {
                                typeKey = new EntryKey(typeRef.GetGloballyUniqueId());
                            }
                            else
                            {
                                CRefPath            path  = new CRefPath(typeRef);
                                Documentation.Entry found = LiveDocumentorFile.Singleton.LiveDocument.Find(path);
                                if (found != null)
                                {
                                    typeKey  = new EntryKey(found.Key);
                                    typeName = found.Name;
                                }
                                else
                                {
                                    typeKey = null;
                                }
                            }
                            typeName = typeRef.GetDisplayName(false);
                        }
                        List <Block> paramDescription = new List <Block>();
                        if (paramComment != null && paramComment.Description != null)
                        {
                            paramDescription = paramComment.Description;
                        }
                        parameters.Add(methodParam.Name, typeName, method.Assembly, typeKey, paramDescription);
                    }
                }
                if (parameters != null)
                {
                    this.Blocks.Add(parameters);
                }
            }
        }