public void SubList(TypeComments typeComments) { var s = MarkdownHelper.RenderSubList(typeComments); if (!string.IsNullOrEmpty(s)) { sb.Append(s); } }
private static void AppendBodyForEnum(MarkdownBuilder mb, TypeComments typeComments) { var enums = Enum.GetNames(typeComments.Type) .Select(x => new { Value = (int)Enum.Parse(typeComments.Type, x), Name = x, Description = (Enum.Parse(typeComments.Type, x) as Enum) !.GetDescription(), })
public static string Render(TypeComments typeComments) { var mb = new MarkdownBuilder(); AppendHeaderForType(mb, typeComments); AppendTypeBox(mb, typeComments); if (typeComments.Type.IsEnum) { AppendBodyForEnum(mb, typeComments); } else { AppendBodyForClass(mb, typeComments); } return(mb.ToString()); }
private static void AppendTypeBox(MarkdownBuilder mb, TypeComments typeComments) { var sb = new StringBuilder(); var stat = typeComments.Type.IsAbstract && typeComments.Type.IsSealed ? "static " : string.Empty; var @abstract = typeComments.Type.IsAbstract && !typeComments.Type.IsInterface && !typeComments.Type.IsSealed ? "abstract " : string.Empty; var classOrStructOrEnumOrInterface = typeComments.Type.IsInterface ? "interface" : typeComments.Type.IsEnum ? "enum" : typeComments.Type.IsValueType ? "struct" : "class"; var impl = string.Empty; if (!typeComments.Type.IsEnum) { impl = string.Join( ", ", new[] { typeComments.Type.BaseType } .Concat(typeComments.Type.GetInterfaces()) .Where(x => x != null && x != typeof(object) && x != typeof(ValueType) && !"System.Runtime.InteropServices".Equals(x.Namespace, StringComparison.Ordinal)) .Select(x => x !.BeautifyName())); } sb.AppendLine(impl.Length > 0 ? $"public {stat}{@abstract}{classOrStructOrEnumOrInterface} {typeComments.Type.BeautifyName(false, true)} : {impl}" : $"public {stat}{@abstract}{classOrStructOrEnumOrInterface} {typeComments.Type.BeautifyName(false, true)}"); mb.Code("csharp", sb.ToString()); mb.AppendLine(); }
private static void AppendHeaderForType(MarkdownBuilder mb, TypeComments typeComments) { mb.AppendLine(); mb.AppendLine("<br />"); mb.AppendLine(); mb.Header(2, typeComments.Type.BeautifyName(false, true)); var summary = typeComments.CommentLookup[typeComments.Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? string.Empty; if (summary.Length > 0) { mb.AppendLine(summary); var remarks = typeComments.CommentLookup[typeComments.Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Remarks ?? string.Empty; if (!string.IsNullOrEmpty(remarks)) { mb.AppendLine($"<p><b>Remarks:</b> {remarks}</p>"); } var code = typeComments.CommentLookup[typeComments.Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Code ?? string.Empty; if (!string.IsNullOrEmpty(code)) { mb.AppendLine("<b>Code usage:</b>"); mb.Code("csharp", code); } var example = typeComments.CommentLookup[typeComments.Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Example ?? string.Empty; if (!string.IsNullOrEmpty(example)) { mb.AppendLine("<b>Code example:</b>"); mb.Code("csharp", example); } } mb.AppendLine(); }
public static string?RenderSubList(TypeComments typeComments) { if (typeComments.Type.IsEnum) { return(null); } var mb = new MarkdownBuilder(); var staticFields = GetStaticFields(typeComments.Type); if (staticFields.Length > 0) { mb.Append(" - Static Fields"); mb.AppendLine(); var list = staticFields .Select(x => x.BeautifyName(false, true, true)) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var staticProperties = GetStaticProperties(typeComments.Type); if (staticProperties.Length > 0) { mb.Append(" - Static Properties"); mb.AppendLine(); var list = staticProperties .Select(x => x.Name) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var staticEvents = GetStaticEvents(typeComments.Type); if (staticEvents.Length > 0) { mb.Append(" - Static Events"); mb.AppendLine(); var list = staticEvents .Select(x => x.Name) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var staticMethods = GetStaticMethods(typeComments.Type); if (staticMethods.Length > 0) { mb.Append(" - Static Methods"); mb.AppendLine(); var list = staticMethods .Select(x => x.BeautifyName(false, true)) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var fields = GetFields(typeComments.Type); if (fields.Length > 0) { mb.Append(" - Fields"); mb.AppendLine(); var list = fields .Select(x => x.BeautifyName(false, true, true)) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var properties = GetProperties(typeComments.Type); if (properties.Length > 0) { mb.Append(" - Properties"); mb.AppendLine(); var list = properties .Select(x => x.Name) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var events = GetEvents(typeComments.Type); if (events.Length > 0) { mb.Append(" - Events"); mb.AppendLine(); var list = events .Select(x => x.Name) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } var methods = GetMethods(typeComments.Type); if (methods.Length > 0) { mb.Append(" - Methods"); mb.AppendLine(); var list = methods .Select(x => x.BeautifyName(false, true)) .OrderBy(x => x) .ToList(); AppendIndentedLines(mb, list); } return(mb.ToString()); }
public void AssertParam(TypeComments comments, int paramIndex, string name, string text) { Assert.AreEqual(name, comments.Parameters[paramIndex].Item1); Assert.AreEqual(text, comments.Parameters[paramIndex].Item2); }