コード例 #1
0
        public static void WriteContentTo(this XElement element, DocumentationWriter writer, bool inlineOnly = false)
        {
            using (IEnumerator <XNode> en = element.Nodes().GetEnumerator())
            {
                if (en.MoveNext())
                {
                    XNode node = null;

                    bool isFirst = true;
                    bool isLast  = false;

                    do
                    {
                        node = en.Current;

                        isLast = !en.MoveNext();

                        if (node is XText t)
                        {
                            string value = t.Value;
                            value = TextUtility.RemoveLeadingTrailingNewLine(value, isFirst, isLast);

                            if (inlineOnly)
                            {
                                value = TextUtility.ToSingleLine(value);
                            }

                            writer.WriteString(value);
                        }
                        else if (node is XElement e)
                        {
                            switch (XmlElementNameKindMapper.GetKindOrDefault(e.Name.LocalName))
                            {
                            case XmlElementKind.C:
                            {
                                string value = e.Value;
                                value = TextUtility.ToSingleLine(value);
                                writer.WriteInlineCode(value);
                                break;
                            }

                            case XmlElementKind.Code:
                            {
                                if (inlineOnly)
                                {
                                    break;
                                }

                                string value = e.Value;
                                value = TextUtility.RemoveLeadingTrailingNewLine(value);

                                writer.WriteCodeBlock(value);

                                break;
                            }

                            case XmlElementKind.List:
                            {
                                if (inlineOnly)
                                {
                                    break;
                                }

                                string type = e.Attribute("type")?.Value;

                                if (!string.IsNullOrEmpty(type))
                                {
                                    switch (type)
                                    {
                                    case "bullet":
                                    {
                                        WriteList(writer, e.Elements());
                                        break;
                                    }

                                    case "number":
                                    {
                                        WriteList(writer, e.Elements(), isOrdered: true);
                                        break;
                                    }

                                    case "table":
                                    {
                                        WriteTable(writer, e.Elements());
                                        break;
                                    }

                                    default:
                                    {
                                        Debug.Fail(type);
                                        break;
                                    }
                                    }
                                }

                                break;
                            }

                            case XmlElementKind.Para:
                            {
                                writer.WriteLine();
                                writer.WriteLine();
                                WriteContentTo(e, writer);
                                writer.WriteLine();
                                writer.WriteLine();
                                break;
                            }

                            case XmlElementKind.ParamRef:
                            {
                                string parameterName = e.Attribute("name")?.Value;

                                if (parameterName != null)
                                {
                                    writer.WriteBold(parameterName);
                                }

                                break;
                            }

                            case XmlElementKind.See:
                            {
                                string commentId = e.Attribute("cref")?.Value;

                                if (commentId != null)
                                {
                                    ISymbol symbol = writer.DocumentationModel.GetFirstSymbolForDeclarationId(commentId);

                                    //XTODO: repair roslyn documentation
                                    Debug.Assert(symbol != null ||
                                                 commentId == "T:Microsoft.CodeAnalysis.CSharp.SyntaxNode" ||
                                                 commentId == "T:Microsoft.CodeAnalysis.CSharp.SyntaxToken" ||
                                                 commentId == "T:Microsoft.CodeAnalysis.CSharp.SyntaxTrivia" ||
                                                 commentId == "T:Microsoft.CodeAnalysis.VisualBasic.SyntaxNode" ||
                                                 commentId == "T:Microsoft.CodeAnalysis.VisualBasic.SyntaxToken" ||
                                                 commentId == "T:Microsoft.CodeAnalysis.VisualBasic.SyntaxTrivia", commentId);

                                    if (symbol != null)
                                    {
                                        writer.WriteLink(symbol, SymbolDisplayFormats.TypeNameAndContainingTypesAndTypeParameters, SymbolDisplayAdditionalMemberOptions.UseItemPropertyName | SymbolDisplayAdditionalMemberOptions.UseOperatorName);
                                    }
                                    else
                                    {
                                        writer.WriteBold(TextUtility.RemovePrefixFromDocumentationCommentId(commentId));
                                    }
                                }

                                break;
                            }

                            case XmlElementKind.TypeParamRef:
                            {
                                string typeParameterName = e.Attribute("name")?.Value;

                                if (typeParameterName != null)
                                {
                                    writer.WriteBold(typeParameterName);
                                }

                                break;
                            }

                            case XmlElementKind.Example:
                            case XmlElementKind.Exception:
                            case XmlElementKind.Exclude:
                            case XmlElementKind.Include:
                            case XmlElementKind.InheritDoc:
                            case XmlElementKind.Param:
                            case XmlElementKind.Permission:
                            case XmlElementKind.Remarks:
                            case XmlElementKind.Returns:
                            case XmlElementKind.SeeAlso:
                            case XmlElementKind.Summary:
                            case XmlElementKind.TypeParam:
                            case XmlElementKind.Value:
                            {
                                break;
                            }

                            default:
                            {
                                Debug.Fail(e.Name.LocalName);
                                break;
                            }
                            }
                        }
                        else
                        {
                            Debug.Fail(node.NodeType.ToString());
                        }

                        isFirst = false;
                    }while (!isLast);
                }
            }
        }
コード例 #2
0
 internal XmlElementKind GetElementKind()
 {
     return(XmlElementNameKindMapper.GetKindOrDefault(LocalName));
 }
コード例 #3
0
 internal bool IsElementKind(XmlElementKind kind)
 {
     return(XmlElementNameKindMapper.GetKindOrDefault(LocalName) == kind);
 }