Beispiel #1
0
        private static Block ParseBlock(AssemblyDef assembly, XmlCodeElement element, ParsingSession session)
        {
            TraceHelper.WriteLine("parsing-block: e({0})", element.Element.ToString());

            CrefEntryKey crefEntryKey;
            Inline       link;
            string       displayName;

            switch (element.Element)
            {
            // Invalid inline elements
            case XmlCodeElements.C:
            case XmlCodeElements.ParamRef:
            case XmlCodeElements.See:
            case XmlCodeElements.SeeAlso:
            case XmlCodeElements.Text:
            case XmlCodeElements.TypeParamRef:
                InvalidOperationException ex = new InvalidOperationException(
                    "Found an inline element where a block level element was expected."
                    );
                ex.Data["element"] = element;
                throw ex;

            case XmlCodeElements.Include:
                InvalidOperationException includeEx = new InvalidOperationException(
                    "Found an include comment element, the c# parser has failed."
                    );
                includeEx.Data["element"] = element;
                throw includeEx;

            // End points
            case XmlCodeElements.Code:
                return(new Code(element.Text));

            case XmlCodeElements.Exception:
                ExceptionXmlCodeElement exceptionElement = element as ExceptionXmlCodeElement;

                if (Parser.ResolveMember(exceptionElement.Text, exceptionElement.Member, assembly, out crefEntryKey, out displayName))
                {
                    link = link = Parser.CreateHyperlink(crefEntryKey, exceptionElement.Member.TypeName);
                }
                else
                {
                    if (string.IsNullOrEmpty(displayName))
                    {
                        link = new Run(exceptionElement.Member.TypeName);
                    }
                    else
                    {
                        link = new Run(displayName);
                    }
                }

                return(new ExceptionEntry(link, Parser.Parse(assembly, element as ExceptionXmlCodeElement)));

            case XmlCodeElements.Example:
                ExampleXmlCodeElement exampleElement = element as ExampleXmlCodeElement;
                return(new Example(Parser.Parse(assembly, exampleElement)));

            case XmlCodeElements.Para:
                ParaXmlCodeElement paraElement = element as ParaXmlCodeElement;
                return(new Para(Parser.Parse(assembly, paraElement)));

            case XmlCodeElements.Permission:
                PermissionXmlCodeElement permissionElement = element as PermissionXmlCodeElement;

                if (Parser.ResolveMember(permissionElement.Text, permissionElement.Member, assembly, out crefEntryKey, out displayName))
                {
                    link = link = Parser.CreateHyperlink(crefEntryKey, permissionElement.Member.TypeName);
                }
                else
                {
                    if (string.IsNullOrEmpty(displayName))
                    {
                        link = new Run(permissionElement.Member.TypeName);
                    }
                    else
                    {
                        link = new Run(displayName);
                    }
                }

                return(new PermissionEntry(link, Parser.Parse(assembly, element as PermissionXmlCodeElement)));

            case XmlCodeElements.Remarks:
                return(new Remarks(Parser.Parse(assembly, element as RemarksXmlCodeElement)));

            case XmlCodeElements.Returns:
                return(new Returns(Parser.Parse(assembly, element as ReturnsXmlCodeElement)));

            case XmlCodeElements.Summary:
                return(new Summary(Parser.Parse(assembly, element as SummaryXmlCodeElement)));

            case XmlCodeElements.Value:
                return(new Value(Parser.Parse(assembly, element as ValueXmlCodeElement)));

            case XmlCodeElements.Param:
                return(new Param(((ParamXmlCodeElement)element).Name, Parser.Parse(assembly, element as ParamXmlCodeElement)));

            case XmlCodeElements.TypeParam:
                TypeParamXmlCodeElement typeParamElement = (TypeParamXmlCodeElement)element;
                return(new TypeParamEntry(typeParamElement.Name, typeParamElement.Text));

            case XmlCodeElements.List:
                ListXmlCodeElement listElement = (ListXmlCodeElement)element;
                return(Parser.ParseList(assembly, listElement));

            case XmlCodeElements.Term:
            case XmlCodeElements.Description:
                Section termOrDescription = new Section();
                termOrDescription.Blocks.AddRange(Parser.Parse(assembly, (XmlContainerCodeElement)element));
                return(termOrDescription);

                break;
            }

            throw new Exception("WTF, block parsing error");
        }
Beispiel #2
0
        /// <summary>
        /// Parses the ListXmlCodeElement in to its correct FlowDocument representation.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        private static Block ParseList(AssemblyDef assembly, ListXmlCodeElement element)
        {
            Block parsedBlock = null;

            switch (element.ListType)
            {
            case Reflection.Comments.ListTypes.Bullet:
            case Reflection.Comments.ListTypes.Number:
                List list = new List();
                if (element.ListType == Reflection.Comments.ListTypes.Number)
                {
                    list.InternalList.MarkerStyle = System.Windows.TextMarkerStyle.Decimal;
                }
                else
                {
                    list.InternalList.MarkerStyle = System.Windows.TextMarkerStyle.Disc;
                }

                // only use list items, headers, even if defined, are not used in normal lists
                foreach (ListItemXmlCodeElement listItem in element.Elements.FindAll(e => e is ListItemXmlCodeElement))
                {
                    ListItem item = new ListItem();
                    item.Blocks.AddRange(Parser.Parse(assembly, listItem));
                    list.InternalList.ListItems.Add(item);
                }

                parsedBlock = list;
                break;

            case Reflection.Comments.ListTypes.Table:
                SummaryTable table;

                // find the header item and use the titles or use defaults
                ListHeaderXmlCodeElement headerElement = (ListHeaderXmlCodeElement)element.Elements.Find(e => e is ListHeaderXmlCodeElement);
                if (headerElement != null && headerElement.Elements.Count == 2)
                {
                    TermXmlCodeElement        termElement        = (TermXmlCodeElement)headerElement.Elements.Find(e => e is TermXmlCodeElement);
                    DescriptionXmlCodeElement descriptionElement = (DescriptionXmlCodeElement)headerElement.Elements.Find(e => e is DescriptionXmlCodeElement);

                    Section term        = new Section();
                    Section description = new Section();
                    term.Blocks.AddRange(Parser.Parse(assembly, termElement));
                    description.Blocks.AddRange(Parser.Parse(assembly, descriptionElement));

                    table = new SummaryTable(term, description, false);
                }
                else
                {
                    table = new SummaryTable("Term", "Description", false);
                }

                foreach (ListItemXmlCodeElement listItem in element.Elements.FindAll(e => e is ListItemXmlCodeElement))
                {
                    TermXmlCodeElement        termElement        = (TermXmlCodeElement)listItem.Elements.Find(e => e is TermXmlCodeElement);
                    DescriptionXmlCodeElement descriptionElement = (DescriptionXmlCodeElement)listItem.Elements.Find(e => e is DescriptionXmlCodeElement);

                    Section term        = new Section();
                    Section description = new Section();

                    if (termElement != null)
                    {
                        term.Blocks.AddRange(Parser.Parse(assembly, termElement));
                    }
                    else if (element.Elements != null && element.Elements.Count > 0)
                    {
                        term.Blocks.Add(new Paragraph(new Run(element.Elements[0].Text)));
                    }

                    if (descriptionElement != null)
                    {
                        description.Blocks.AddRange(Parser.Parse(assembly, descriptionElement));
                    }
                    else if (element.Elements != null && element.Elements.Count > 1)
                    {
                        term.Blocks.Add(new Paragraph(new Run(element.Elements[1].Text)));
                    }

                    table.AddItem(term, description);
                }

                parsedBlock = table;
                break;
            }
            return(parsedBlock);
        }
Beispiel #3
0
 /// <summary>
 /// Initialises a new instance of the ListXmlElementRenderer class.
 /// </summary>
 /// <param name="associatedEntry"></param>
 /// <param name="element"></param>
 public ListXmlElementRenderer(Entry associatedEntry, ListXmlCodeElement element)
 {
     AssociatedEntry = associatedEntry;
     _element        = element;
 }