void BuildTable <T>(MarkdownBuilder mb, string label, T[] array, IEnumerable <XmlDocumentComment> docs, Func <T, string> type, Func <T, string> name, Func <T, string> finalName) { if (array.Any()) { mb.AppendLine($"##\t{label}"); mb.AppendLine(); string[] head = (this.type.IsEnum) ? new[] { "Value", "Name", "Summary" } : new[] { "Type", "Name", "Summary" }; IEnumerable <T> seq = array; if (!this.type.IsEnum) { seq = array.OrderBy(x => name(x)); } var data = seq.Select(item2 => { var summary = docs.FirstOrDefault(x => x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`"))?.Summary ?? ""; return(new[] { //MarkdownBuilder.MarkdownCodeQuote(), type(item2).Replace("|", @"\|"), finalName(item2).Replace("|", @"\|"), summary.Replace("|", @"\|") }); }); mb.Table(head, data); mb.AppendLine(); } }
void BuildTable <T>(MarkdownBuilder mb, string label, IReadOnlyList <T> array, IEnumerable <XmlDocumentComment> docs, Func <T, string> type, Func <T, string> name, Func <T, string> finalName) { if (array.Any()) { mb.AppendLine(label); mb.AppendLine(); string[] head = new[] { "Name", "Description" }; IEnumerable <T> seq = array; if (!this.type.IsEnum) { seq = array.OrderBy(x => name(x)); } var data = seq.Select(item2 => { var summary = docs.FirstOrDefault(x => x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`"))?.Summary ?? ""; //if (summary.Contains("`1") && summary.Contains('[') && summary.StartsWith("Removes the specified event handler, causing")) //{ // var match = Regex.Match(summary, @".*\[(.*)\].*"); // if (!match.Success) // { // return new[] { finalName(item2), summary }; // } // var typeString = match.Groups[1].Value; // var indexOfSuffix = typeString.LastIndexOf("`2."); // if (indexOfSuffix > -1) // { // typeString = typeString.Remove(indexOfSuffix + 2); // } // var methodInfo = item2 as MethodInfo; // var theType = Assembly // .Load(File.ReadAllBytes("System.Reactive.dll")) // .GetTypes() // .FirstOrDefault(x => x.FullName.Equals(typeString)); // Console.WriteLine(summary); // summary = summary.Replace(typeString, Beautifier.BeautifyType(theType)); //} return(new[] { finalName(item2), summary }); }); mb.Table(head, data); mb.AppendLine(); } }
void BuildTable <T>(MarkdownBuilder mb, string label, T[] array, IEnumerable <XmlDocumentComment> docs, Func <T, string> type, Func <T, string> name, Func <T, string> finalName) { if (array.Any()) { mb.AppendLine(label); mb.AppendLine(); string[] head = new[] { "Type", "Name", "Summary" }; IEnumerable <T> seq = array; IEnumerable <string[]> data = seq.Select(item2 => { string summary = docs.FirstOrDefault(x => x.MemberName == name(item2))?.Summary ?? ""; return(new string[] { MarkdownBuilder.MarkdownCodeQuote(type(item2)), finalName(item2), summary }); }); mb.Table(head, data); mb.AppendLine(); } }
void BuildTable <T>(MarkdownBuilder mb, string label, T[] array, IEnumerable <XmlDocumentComment> docs, Func <T, string> type, Func <T, string> name, Func <T, string> finalName) { if (array.Any()) { mb.AppendLine(label); mb.AppendLine(); string[] head = (this.type.IsEnum) ? new[] { "Value", "Name", "Summary" } : new[] { "Type", "Name", "Summary" }; IEnumerable <T> seq = array; if (!this.type.IsEnum) { seq = array.OrderBy(x => name(x)); } var data = seq.Select(item2 => { var candidates = docs.Where(x => x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`")).ToArray(); if (candidates.Count() >= 2 && item2 is MethodBase) { // Attempt to identify method overloads var methodParameterNames = (item2 as MethodBase).GetParameters().Select(p => p.Name); var overloadCandidates = candidates.Where(x => x.Parameters.Keys.SequenceEqual(methodParameterNames)).ToArray(); if (overloadCandidates.Any()) { candidates = overloadCandidates; } } var summary = candidates.FirstOrDefault()?.Summary ?? ""; return(new[] { MarkdownBuilder.MarkdownCodeQuote(type(item2)), finalName(item2), summary }); }); mb.Table(head, data); mb.AppendLine(); } }
private void BuildTable <T> (MarkdownBuilder mb, string label, T[] array, IEnumerable <XmlDocumentComment> docs, Func <T, string> type, Func <T, string> name, Func <T, string> finalName) { if (array.Any()) { mb.Header(4, label); mb.AppendLine(); var head = Type.IsEnum ? new[] { "Value", "Name", "Summary" } : new[] { "Type", "Name", "Summary" }; IEnumerable <T> seq = array; if (!Type.IsEnum) { seq = array.OrderBy(x => name(x)); } var data = seq.Select(item2 => { var summary = docs.FirstOrDefault(x => x.MemberName == name(item2) || x.MemberName.StartsWith(name(item2) + "`"))?.Summary ?? ""; return(new[] { type(item2), finalName(item2), summary }); }); mb.Table(head, data); mb.AppendLine(); } }
public override string ToString() { var mb = new MarkdownBuilder(); var typeCategory = type.IsClass ? " Class" : type.IsInterface ? " Interface" : string.Empty; mb.HeaderWithCode(2, Beautifier.BeautifyType(type, false) + typeCategory); mb.AppendLine(); mb.AppendLine($"Namespace: {type.Namespace}"); mb.AppendLine(); mb.AppendLine($"Assembly: {type.Assembly.ManifestModule.Name}"); mb.AppendLine(); var summary = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? ""; if (summary != "") { mb.AppendLine(summary); mb.AppendLine(); } var sb = new StringBuilder(); var isStatic = type.IsAbstract && type.IsSealed; var @sealed = !type.IsAbstract && type.IsSealed ? "sealed " : ""; var stat = isStatic ? "static " : ""; var abst = (type.IsAbstract && !type.IsInterface && !type.IsSealed) ? "abstract " : ""; var classOrStructOrEnumOrInterface = type.IsInterface ? "interface" : type.IsEnum ? "enum" : type.IsValueType ? "struct" : "class"; sb.AppendLine($"public {stat}{@sealed}{abst}{classOrStructOrEnumOrInterface} {Beautifier.BeautifyType(type, true)}"); var impl = string.Join(", ", new[] { type.BaseType }.Concat(type.GetInterfaces()).Where(x => x != null && x != typeof(object) && x != typeof(ValueType)).Select(x => Beautifier.BeautifyType(x))); if (impl != "") { sb.AppendLine(" : " + impl); } mb.Code("csharp", sb.ToString()); var typeParameters = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.TypeParameters; if (typeParameters.Count > 0) { mb.Header(3, "Type Parameters"); mb.AppendLine(); mb.Table(new[] { "Name", "Summary" }, typeParameters.Select(x => new[] { x.Key, x.Value })); } mb.AppendLine(); if (type.IsEnum) { var underlyingEnumType = Enum.GetUnderlyingType(type); var enums = Enum.GetNames(type) .Select(x => new { Name = x, Value = (Convert.ChangeType(Enum.Parse(type, x), underlyingEnumType)) }) .OrderBy(x => x.Value) .ToArray(); BuildTable(mb, "Enum", enums, commentLookup[type.FullName], x => x.Value.ToString(), x => x.Name, x => x.Name); } else { BuildTable(mb, "Constructors", GetConstructors(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.DeclaringType), x => "#ctor", x => Beautifier.ToMarkdownConstructorInfo(x)); BuildTable(mb, "Fields", GetFields(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name); BuildTable(mb, "Properties", GetProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name); BuildTable(mb, "Events", GetEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name); BuildTable(mb, "Methods", GetMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfoWithoutParamNames(x)); BuildTable(mb, "Static Fields", GetStaticFields(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name); BuildTable(mb, "Static Properties", GetStaticProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name); BuildTable(mb, "Static Methods", GetStaticMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x)); BuildTable(mb, "Static Events", GetStaticEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name); } return(mb.ToString()); }