public static MarkdownableType[] Load(string dllPath, string namespaceMatch) { string xmlPath = Path.Combine( Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml"); XmlDocumentComment[] comments = new XmlDocumentComment[0]; if (File.Exists(xmlPath)) { comments = VSDocParser.ParseXmlComment(XDocument.Parse(File.ReadAllText(xmlPath)), namespaceMatch); } ILookup <string, XmlDocumentComment> commentsLookup = comments.ToLookup(x => x.ClassName); Regex namespaceRegex = !string.IsNullOrEmpty(namespaceMatch) ? new Regex(namespaceMatch) : null; return(new[] { Assembly.LoadFrom(dllPath) } .SelectMany( x => { try { return x.GetTypes(); } catch (ReflectionTypeLoadException ex) { return ex.Types.Where(t => t != null); } catch { return Type.EmptyTypes; } }) .Where(x => x != null) .Where( x => x.IsPublic && !typeof(Delegate).IsAssignableFrom(x) && !x.GetCustomAttributes <ObsoleteAttribute>().Any()) .Where(x => IsRequiredNamespace(x, namespaceRegex)) .Select(x => new MarkdownableType(x, commentsLookup)) .ToArray()); }
private void BuildTable <T>(MarkdownBuilder mb, string label, T[] array, Func <T, string> type, Func <T, string> name, Func <T, string> finalName, Func <T, XmlDocumentComment, bool> get) { if (array.Any()) { mb.Header(2, label); mb.AppendLine(); IEnumerable <T> seq = array; if (!this.type.IsEnum) { seq = array.OrderBy(name); } IEnumerable <MarkdownBuilder.DropdownItem> data = seq.Select( item2 => { XmlDocumentComment _lookupInterfaces(Type t) { XmlDocumentComment lookup = null; Type[] interfaces = t.GetInterfaces(); for (int i = 0; i < interfaces.Length && lookup == null; i++) { lookup = commentLookup[interfaces[i].FullName] .FirstOrDefault( x => (x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`")) && get(item2, x)); if (lookup == null || (lookup.Summary?.Trim() .Equals( "inheritdoc", StringComparison.InvariantCultureIgnoreCase) ?? true)) { lookup = _lookupInterfaces(interfaces[i]); } } return(lookup); } XmlDocumentComment _lookupType(Type t) { if (t == null) { return(null); } XmlDocumentComment lookup = commentLookup[t.FullName] .FirstOrDefault( x => (x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`")) && get(item2, x)); if (lookup == null || (lookup.Summary?.Trim() .Equals( "inheritdoc", StringComparison.InvariantCultureIgnoreCase) ?? true)) { lookup = _lookupInterfaces(t) ?? _lookupType(t.BaseType); } return(lookup); } return(new MarkdownBuilder.DropdownItem { Type = MarkdownBuilder.MarkdownCodeQuote(type(item2)), Name = finalName(item2), XmlDocumentComment = _lookupType(this.type) }); }); mb.Dropdown(data); mb.AppendLine("___"); } }