예제 #1
0
 public XElement GetTypeParameter(string name)
 {
     return(GetNamedItem(_TypeParameters, name) ?? _ExplicitInheritDoc?.GetTypeParameter(name));
 }
예제 #2
0
        public ThemedTipDocument RenderXmlDoc(ISymbol symbol, XmlDoc doc)
        {
            var    tip             = new ThemedTipDocument();
            var    summary         = doc.GetDescription(symbol);
            XmlDoc inheritDoc      = null;
            bool   showSummaryIcon = true;

            #region Summary
            if (summary == null &&
                Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromBaseType))
            {
                summary = doc.GetInheritedDescription(symbol, out inheritDoc);
                if (inheritDoc != null && summary != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.ReferencedXmlDoc, new ThemedTipText()
                                                      .Append(R.T_DocumentationFrom)
                                                      .AddSymbol(inheritDoc.Symbol.ContainingSymbol, false, _SymbolFormatter)
                                                      .Append(".")
                                                      .AddSymbol(inheritDoc.Symbol, true, _SymbolFormatter)
                                                      .Append(":"))
                               );
                    showSummaryIcon = false;
                }
            }
            if (summary != null &&
                (summary.Name.LocalName != XmlDocNodeName || Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.TextOnlyDoc)))
            {
                ParagraphCount = 0;
                Render(summary, tip, showSummaryIcon);
                if (inheritDoc == null)
                {
                    tip.Tag = ParagraphCount;
                }
            }
            #endregion
            #region Type parameter
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.TypeParameters) &&
                (symbol.Kind == SymbolKind.Method || symbol.Kind == SymbolKind.NamedType))
            {
                var typeParams = symbol.GetTypeParameters();
                if (typeParams.IsDefaultOrEmpty == false)
                {
                    var para = new ThemedTipParagraph(IconIds.TypeParameters);
                    foreach (var param in typeParams)
                    {
                        var p = doc.GetTypeParameter(param.Name);
                        if (p == null)
                        {
                            continue;
                        }
                        if (para.Content.Inlines.FirstInline != null)
                        {
                            para.Content.AppendLine();
                        }
                        para.Content
                        .Append(param.Name, _SymbolFormatter.TypeParameter)
                        .Append(": ")
                        .AddXmlDoc(p, this);
                    }
                    if (para.Content.Inlines.FirstInline != null)
                    {
                        tip.Append(para);
                    }
                }
            }
            #endregion
            #region Returns
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.ReturnsDoc) &&
                (symbol.Kind == SymbolKind.Method ||
                 symbol.Kind == SymbolKind.NamedType && ((INamedTypeSymbol)symbol).TypeKind == TypeKind.Delegate))
            {
                var returns = doc.Returns ?? doc.ExplicitInheritDoc?.Returns ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Returns != null)?.Returns;
                if (returns != null && returns.FirstNode != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.Return, new ThemedTipText()
                                                      .Append(R.T_Returns, true)
                                                      .Append(returns == doc.Returns ? ": " : (R.T_Inherited + ": "))
                                                      .AddXmlDoc(returns, this))
                               );
                }
            }
            #endregion
            #region Remarks
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.RemarksDoc) &&
                symbol.Kind != SymbolKind.Parameter &&
                symbol.Kind != SymbolKind.TypeParameter)
            {
                var remarks = doc.Remarks ?? doc.ExplicitInheritDoc?.Remarks ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Remarks != null)?.Remarks;
                if (remarks != null && remarks.FirstNode != null)
                {
                    tip.Append(new ThemedTipParagraph(IconIds.RemarksXmlDoc, new ThemedTipText()
                                                      .Append(R.T_Remarks, true)
                                                      .Append(remarks == doc.Remarks ? ": " : (R.T_Inherited + ": "))
                                                      ))
                    .Append(new ThemedTipParagraph(new ThemedTipText().AddXmlDoc(remarks, this)));
                }
            }
            #endregion
            #region SeeAlso
            if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.SeeAlsoDoc))
            {
                var seeAlsos = doc.SeeAlso ?? doc.ExplicitInheritDoc?.SeeAlso ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.SeeAlso != null)?.SeeAlso;
                if (seeAlsos != null)
                {
                    var seeAlso = new ThemedTipText()
                                  .Append(R.T_SeeAlso, true)
                                  .Append(seeAlsos == doc.SeeAlso ? ": " : (R.T_Inherited + ": "));
                    bool hasItem = false;
                    foreach (var item in seeAlsos)
                    {
                        if (hasItem)
                        {
                            seeAlso.Append(", ");
                        }
                        RenderXmlDocSymbol(item.Attribute("cref").Value, seeAlso.Inlines, SymbolKind.Alias);
                        hasItem = true;
                    }
                    tip.Append(new ThemedTipParagraph(IconIds.SeeAlsoXmlDoc, seeAlso));
                }
            }
            #endregion
            var example = doc.Example ?? doc.ExplicitInheritDoc?.Example ?? doc.InheritedXmlDocs.FirstOrDefault(i => i.Example != null)?.Example;
            if (example != null)
            {
                tip.Append(new ThemedTipParagraph(IconIds.ExampleXmlDoc, new ThemedTipText()
                                                  .Append(R.T_Example, true)
                                                  .Append(example == doc.Example ? ": " : (R.T_Inherited + ": "))
                                                  ))
                .Append(new ThemedTipParagraph(new ThemedTipText().AddXmlDoc(example, this)));
            }
            return(tip);
        }