private SDToken GetSeeRef(XmlDocumentationElement xmlElement) { try { var sdToken = new SDSeeToken(); if (xmlElement.ReferencedEntity != null) { var identifier = xmlElement.ReferencedEntity.DeclaringType != null ? xmlElement.ReferencedEntity.DeclaringType.GetIdentifier() : string.Empty; sdToken.Name = xmlElement.ReferencedEntity.Name; sdToken.Namespace = xmlElement.ReferencedEntity.Namespace; sdToken.DeclaringType = identifier; sdToken.Text = xmlElement.ReferencedEntity.Name; } else { sdToken.Name = xmlElement.GetAttribute("cref"); } return(sdToken); } catch (Exception) { return(null); } }
protected override object CreateFancyDescription() { var ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType; string header = ambience.ConvertSymbol(Entity); var documentation = XmlDocumentationElement.Get(Entity); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var b = new CSharpDocumentationBuilder(ambience); b.AddCodeBlock(header, keepLargeMargin: true); if (documentation != null) { foreach (var child in documentation.Children) { b.AddDocumentationElement(child); } } var flowDocument = b.CreateFlowDocument(); flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space return(new FlowDocumentScrollViewer { Document = flowDocument, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }); }
private SDTokenList ParseContentTokens(XmlDocumentationElement xmlElement) { var content = new SDTokenList(); foreach (XmlDocumentationElement element in xmlElement.Children) { var text = Regex.Replace(element.TextContent, "^[ ]{4}", "", RegexOptions.Multiline); if (element.IsTextNode) { content.Add(new SDToken { Role = SDTokenRole.Text, Text = text }); } else { switch (element.Name.ToLower()) { case "see": var seeRef = GetSeeRef(element); if (seeRef != null) { content.Add(seeRef); } break; case "typeparamref": content.Add(new SDToken { Role = SDTokenRole.TypeParamRef, Text = element.GetAttribute("name") }); break; case "paramref": content.Add(new SDToken { Role = SDTokenRole.ParamRef, Text = element.GetAttribute("name") }); break; case "code": content.Add(new SDCodeToken { Text = text, IsInline = false }); break; case "c": content.Add(new SDCodeToken { Text = text, IsInline = true }); break; case "para": content.Add(new SDToken { Text = text, Role = SDTokenRole.Paragraph }); break; } } } return(content); }
public static FlowDocument CreateTooltip(IEntity entity, bool useFullyQualifiedMemberNames = true) { var ambience = AmbienceService.GetCurrentAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType; if (useFullyQualifiedMemberNames) { ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedEntityNames; } string header = ambience.ConvertSymbol(entity); var documentation = XmlDocumentationElement.Get(entity); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; DocumentationUIBuilder b = new DocumentationUIBuilder(ambience); b.AddCodeBlock(header, keepLargeMargin: true); if (documentation != null) { foreach (var child in documentation.Children) { b.AddDocumentationElement(child); } } return(b.CreateFlowDocument()); }
private void AddResultsSection(Dictionary <string, SDTokenList> results, XmlDocumentationElement xmlElement) { if (!string.IsNullOrEmpty(xmlElement.GetAttribute("httpCode"))) { results.Add(xmlElement.GetAttribute("httpCode"), ParseContentTokens(xmlElement)); } else if (!results.ContainsKey("default")) { results.Add("default", ParseContentTokens(xmlElement)); } }
public void CDATAInDocumentation() { Init(@"using System; /// <summary>before<![CDATA[<xml/>]]>after</summary> class Test { } "); var element = XmlDocumentationElement.Get(typeDefinition); Assert.AreEqual(1, element.Children.Count()); Assert.AreEqual("summary", element.Children[0].Name); Assert.AreEqual("before<xml/>after", element.Children[0].TextContent); }
protected override CodeAction GetAction(RefactoringContext context, ThrowStatement node) { var entity = node.GetParent <EntityDeclaration> (); if (entity == null) { return(null); } var rr = context.Resolve(entity) as MemberResolveResult; if (rr == null || rr.IsError) { return(null); } var expr = context.Resolve(node.Expression); if (expr == null || expr.IsError || expr.Type.GetDefinition() == null) { return(null); } var docElement = XmlDocumentationElement.Get(rr.Member); if (docElement == null || docElement.Children.Count == 0) { return(null); } foreach (var de in docElement.Children) { if (de.Name == "exception") { if (de.ReferencedEntity == expr.Type) { return(null); } } } return(new CodeAction( context.TranslateString("Add exception to xml documentation"), script => { var startText = string.Format(" <exception cref=\"{0}\">", expr.Type.GetDefinition().GetIdString()); var comment = new Comment(startText + "</exception>", CommentType.Documentation); script.InsertBefore( SearchInsertionNode(entity.FirstChild) ?? entity, comment ); script.Select(script.GetSegment(comment).Offset + ("///" + startText).Length, 0); }, node )); }
void AddSee(XmlDocumentationElement element) { IEntity referencedEntity = element.ReferencedEntity; if (referencedEntity != null) { if (element.Children.Any()) { Hyperlink link = new Hyperlink(); link.Click += (sender, e) => { MainWindow.Instance.JumpToReference(referencedEntity); }; AddSpan(link, element.Children); } else { AddInline(ConvertReference(referencedEntity)); } } else if (element.GetAttribute("langword") != null) { AddInline(new Run(element.GetAttribute("langword")) { FontFamily = GetCodeFont() }); } else if (element.GetAttribute("href") != null) { Uri uri; if (Uri.TryCreate(element.GetAttribute("href"), UriKind.Absolute, out uri)) { if (element.Children.Any()) { AddSpan(new Hyperlink { NavigateUri = uri }, element.Children); } else { AddInline(new Hyperlink(new Run(element.GetAttribute("href"))) { NavigateUri = uri }); } } } else { // Invalid reference: print the cref value AddText(element.GetAttribute("cref")); } }
FlowDocumentScrollViewer GenerateHeader() { var ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); var documentation = XmlDocumentationElement.Get(Method); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var b = new CSharpDocumentationBuilder(ambience); string parameterName = null; if (Method.Parameters.Count > highlightedParameterIndex) { parameterName = Method.Parameters[highlightedParameterIndex].Name; } b.AddSignatureBlock(stringBuilder.ToString(), formatter.parameterStartOffset, formatter.parameterLength, parameterName); var b2 = new CSharpDocumentationBuilder(ambience); b2.ParameterName = parameterName; b2.ShowAllParameters = false; if (documentation != null) { foreach (var child in documentation.Children) { b2.AddDocumentationElement(child); } } content = new FlowDocumentScrollViewer { Document = b2.CreateFlowDocument(), VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; var flowDocument = b.CreateFlowDocument(); flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space return(new FlowDocumentScrollViewer { Document = flowDocument, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }); }
void GenerateHeader() { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); TokenWriter formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); var documentation = XmlDocumentationElement.Get(Method); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString()); header.Inlines.Clear(); header.Inlines.AddRange(inlineBuilder.CreateRuns()); }
public void InheritedDocumentation() { Init(@"using System; class Derived : Base { /// <summary>Overridden summary</summary><inheritdoc/> public override void Method(); } class Base { /// <summary>Base summary</summary><remarks>Base remarks</remarks> public virtual void Method(); } "); var element = XmlDocumentationElement.Get(typeDefinition.Methods.Single(m => m.Name == "Method")); Assert.AreEqual(2, element.Children.Count()); Assert.AreEqual("summary", element.Children[0].Name); Assert.AreEqual("remarks", element.Children[1].Name); Assert.AreEqual("Overridden summary", element.Children[0].TextContent); Assert.AreEqual("Base remarks", element.Children[1].TextContent); }
public SDLanguageItemCollection <SDDocumentation> ParseDocumentation(IEntity entity) { var docDic = new SDLanguageItemCollection <SDDocumentation>(); try { if (entity != null) { var xmlDoc = XmlDocumentationElement.Get(entity); if (xmlDoc != null) { foreach (XmlDocumentationElement child in xmlDoc.Children) { if (CultureInfo.GetCultures(CultureTypes.NeutralCultures).Any(c => c.TwoLetterISOLanguageName == child.Name.ToLower()) || child.Name.ToLower() == "default") { // TODO //_sdRepository.AddDocumentationLanguage(child.Name.ToLower()); var languageDoc = ParseDocumentation(child.Children); docDic.Add(child.Name.ToLower(), languageDoc); } } //Es wurde keine Sprachunterstützung in der Doku genutzt. //Deswegen wird die Doku einfach als "default" geladen. if (docDic.Count == 0) { var defaultDoc = ParseDocumentation(xmlDoc.Children); docDic.Add("default", defaultDoc); } } } } catch (NullReferenceException ex) { Trace.TraceError(ex.ToString()); } return(docDic); }
public void AddDocumentationElement(XmlDocumentationElement element) { if (element == null) { throw new ArgumentNullException("element"); } if (element.IsTextNode) { AddText(element.TextContent); return; } switch (element.Name) { case "b": AddSpan(new Bold(), element.Children); break; case "i": AddSpan(new Italic(), element.Children); break; case "c": AddSpan(new Span { FontFamily = GetCodeFont() }, element.Children); break; case "code": AddCodeBlock(element.TextContent); break; case "example": if (ShowExample) { AddSection("Example: ", element.Children); } break; case "exception": if (ShowExceptions) { AddException(element.ReferencedEntity, element.Children); } break; case "list": AddList(element.GetAttribute("type"), element.Children); break; //case "note": // throw new NotImplementedException(); case "para": AddParagraph(new Paragraph { Margin = new Thickness(0, 5, 0, 5) }, element.Children); break; case "param": if (ShowAllParameters || (ParameterName != null && ParameterName == element.GetAttribute("name"))) { AddParam(element.GetAttribute("name"), element.Children); } break; case "paramref": AddParamRef(element.GetAttribute("name")); break; case "permission": if (ShowPermissions) { AddPermission(element.ReferencedEntity, element.Children); } break; case "preliminary": if (ShowPreliminary) { AddPreliminary(element.Children); } break; case "remarks": if (ShowRemarks) { AddSection("Remarks: ", element.Children); } break; case "returns": if (ShowReturns) { AddSection("Returns: ", element.Children); } break; case "see": AddSee(element); break; case "seealso": if (inlineCollection != null) { AddSee(element); } else if (ShowSeeAlso) { AddSection(new Run("See also: "), () => AddSee(element)); } break; case "summary": if (ShowSummary) { AddSection("Summary: ", element.Children); } break; case "threadsafety": if (ShowThreadSafety) { AddThreadSafety(ParseBool(element.GetAttribute("static")), ParseBool(element.GetAttribute("instance")), element.Children); } break; case "typeparam": if (ShowTypeParameters) { AddSection("Type parameter " + element.GetAttribute("name") + ": ", element.Children); } break; case "typeparamref": AddText(element.GetAttribute("name")); break; case "value": if (ShowValue) { AddSection("Value: ", element.Children); } break; case "exclude": case "filterpriority": case "overloads": // ignore children break; case "br": AddLineBreak(); break; default: foreach (var child in element.Children) { AddDocumentationElement(child); } break; } }