Esempio n. 1
0
 private static void AppendIndentedLines(MarkdownBuilder mb, IEnumerable <string> list)
 {
     foreach (var item in list)
     {
         mb.Append($"     - {item}");
         mb.AppendLine();
     }
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
        private static void GenerateAndWrites(TypeComments[] typeComments, DirectoryInfo outputPath)
        {
            var homeBuilder = new MarkdownBuilder();

            homeBuilder.AppendLine("<div style='text-align: right'>");
            homeBuilder.AppendLine("[References extended](IndexExtended.md)");
            homeBuilder.AppendLine("</div>");
            homeBuilder.AppendLine();
            homeBuilder.Header(1, "References");
            homeBuilder.AppendLine();

            var homeExtendedBuilder = new MarkdownBuilder();

            homeExtendedBuilder.AppendLine("<div style='text-align: right'>");
            homeExtendedBuilder.AppendLine("[References](Index.md)");
            homeExtendedBuilder.AppendLine("</div>");
            homeExtendedBuilder.AppendLine();
            homeExtendedBuilder.Header(1, "References extended");
            homeExtendedBuilder.AppendLine();

            foreach (var g in typeComments.GroupBy(x => x.Namespace, StringComparer.Ordinal).OrderBy(x => x.Key))
            {
                homeBuilder.HeaderWithLink(2, g.Key, g.Key + ".md");
                homeBuilder.AppendLine();

                homeExtendedBuilder.HeaderWithLink(2, g.Key, g.Key + ".md");
                homeExtendedBuilder.AppendLine();

                var sb = new StringBuilder();
                sb.AppendLine("<div style='text-align: right'>");
                sb.AppendLine();
                sb.AppendLine("[References](Index.md)&nbsp;&nbsp;-&nbsp;&nbsp;[References extended](IndexExtended.md)");
                sb.AppendLine("</div>");
                sb.AppendLine();

                sb.AppendLine($"# {g.Key}");
                foreach (var item in g.OrderBy(x => x.Name))
                {
                    var beautifyItemName1 = item.BeautifyHtmlName;
                    var beautifyItemName2 = item.BeautifyHtmlName
                                            .Replace(",", string.Empty, StringComparison.Ordinal)
                                            .Replace(" ", "-", StringComparison.Ordinal)
                                            .ToLower(GlobalizationConstants.EnglishCultureInfo);

                    homeBuilder.ListLink(beautifyItemName1, g.Key + ".md" + "#" + beautifyItemName2);
                    homeExtendedBuilder.ListLink(beautifyItemName1, g.Key + ".md" + "#" + beautifyItemName2);
                    homeExtendedBuilder.SubList(item);
                    sb.Append(MarkdownHelper.Render(item));
                }

                homeBuilder.AppendLine();
                homeExtendedBuilder.AppendLine();
                sb.AppendLine(GeneratedBy);
                File.WriteAllText(Path.Combine(outputPath.FullName, g.Key + ".md"), sb.ToString());
            }

            homeBuilder.AppendLine(GeneratedBy);
            File.WriteAllText(Path.Combine(outputPath.FullName, "Index.md"), homeBuilder.ToString());

            homeExtendedBuilder.AppendLine(GeneratedBy);
            File.WriteAllText(Path.Combine(outputPath.FullName, "IndexExtended.md"), homeExtendedBuilder.ToString());
        }