Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
 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));
     }
 }
Esempio n. 3
0
        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 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;
			}
		}
		void AddSee(XmlDocumentationElement element)
		{
			IEntity referencedEntity = element.ReferencedEntity;
			if (referencedEntity != null) {
				if (element.Children.Any()) {
					Hyperlink link = new Hyperlink();
					link.Click += CreateNavigateOnClickHandler(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"));
			}
		}
Esempio n. 6
0
        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":
			                if (element.ReferencedEntity != null)
			                {
			                    var identifier = element.ReferencedEntity.DeclaringType != null
                                                        ? element.ReferencedEntity.DeclaringType.GetIdentifier()
			                                            : string.Empty;
			                    content.Add(new SDSeeToken
			                        {
			                            Name = element.ReferencedEntity.Name,
			                            Namespace = element.ReferencedEntity.Namespace,
                                        DeclaringType = identifier != string.Empty ? _sdRepository.GetTypeByIdentifier(identifier) : null,
                                        Text = element.ReferencedEntity.Name
			                        });
			                }
			                else
			                {
			                    content.Add(new SDSeeToken {Name = element.GetAttribute("cref")});
			                }
			                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;
		}