public static bool IsMatchOnMethod(this MethodBase methodInfo, XmlDocumentComment comment) { var isCorrectType = comment.MemberName == methodInfo.GetCommentName(); if (isCorrectType) { if (methodInfo.GetParameters().Count() == comment.Parameters.Count()) { var result = methodInfo.GetParameters().All(b => comment.Parameters.ContainsKey(b.Name + ":" + b.ParameterType.GetCommentTypeString())); if (result) { return(result); } return(methodInfo.GetParameters().All(b => comment.Parameters.ContainsKey(b.Name))); } } return(false); }
/// <summary> /// Builds the markdown method page content /// </summary> /// <param name="item">The markdown method item</param> /// <returns>The markdown content</returns> public string BuildPage(MarkdownMethod item) { Dictionary <string, string> parameterPairs = new Dictionary <string, string>(); Dictionary <string, string> returnPairs = new Dictionary <string, string>(); XmlDocumentComment[] comments = new XmlDocumentComment[0]; MarkdownBuilder mb = new MarkdownBuilder(); var name = Cleaner.CreateFullMethodWithLinks(item, item.As <MarkdownMethod>(), false, true, true); // method name + params name with type var FullName = item.Name + name; var typeZeroHeaders = new[] { "Return", "Name" }; mb.HeaderWithLink(1, item.FullName, item.To(item)); mb.AppendLine(); mb.AppendLine(item.Summary); BuildTable(mb, item, typeZeroHeaders, item); mb.Append("#### Parameters"); mb.AppendLine(); if (File.Exists(MarkdownItemBuilder.xmlPath)) { comments = VSDocParser.ParseXmlParameterComment(XDocument.Parse(File.ReadAllText(MarkdownItemBuilder.xmlPath)), ""); foreach (var comment in comments) { foreach (var param in item.Parameters) { var foundParameterComment = comment.Parameters.FirstOrDefault(x => x.Key == param.Name).Value; if (foundParameterComment != null) { foundParameterComment = foundParameterComment.Substring(0, foundParameterComment.LastIndexOf('<')); foundParameterComment = foundParameterComment.Substring(foundParameterComment.IndexOf('>') + 1); var MethodName = Cleaner.CleanName(comment.MemberName, false, false); // method name + param name + parameter summary if (!parameterPairs.ContainsKey(MethodName + " " + param.Name)) { parameterPairs.Add(MethodName + " " + param.Name, foundParameterComment); } } } } } var numberOfParameters = item.Parameters.Length; for (int i = 1; i <= numberOfParameters; i++) { if (i == numberOfParameters) { ConstructParameter(mb, FullName, parameterPairs, false, i); } else { ConstructParameter(mb, FullName, parameterPairs, true, i); } } mb.AppendLine(); mb.Append("#### Returns"); mb.AppendLine(); Type lookUpType = null; if (item.ItemType == MarkdownItemTypes.Method) { lookUpType = item.As <MarkdownMethod>().ReturnType; } var returned = Cleaner.CreateFullTypeWithLinks(item, lookUpType, false, false); string foundReturnComment = string.Empty; if (File.Exists(MarkdownItemBuilder.xmlPath)) { comments = VSDocParser.ParseXmlComment(XDocument.Parse(File.ReadAllText(MarkdownItemBuilder.xmlPath)), ""); if (comments != null) { foreach (var k in comments) { k.MemberName = Cleaner.CleanName(k.MemberName, false, false); returnPairs[k.MemberName] = k.Returns; } foundReturnComment = returnPairs.FirstOrDefault(x => x.Key == item.Name).Value; } } foundReturnComment = Regex.Replace(foundReturnComment, @"<see cref=""\w:([^\""]*)""\s*\/>", m => VSDocParser.ResolveSeeElement(m, "")); Console.WriteLine(returned); Console.WriteLine(foundReturnComment); mb.Append(returned); mb.AppendLine("<br>"); mb.Append(foundReturnComment); return(mb.ToString()); }