示例#1
0
 public void Dropdown(IEnumerable <DropdownItem> items)
 {
     foreach (DropdownItem item in items)
     {
         if (string.IsNullOrWhiteSpace(item.XmlDocumentComment?.Summary))
         {
             sb.AppendLine($"<dl>&nbsp;&nbsp;&nbsp;&nbsp;{item.Type} {item.Name}<br /></dl>");
             continue;
         }
         sb.Append($"<details><summary>{item.Type} {Regex.Replace(item.Name, @"\r\n?|\n", " ")}</summary><h3>Summary:</h3><p>{Beautifier.ReplaceLinks(item.XmlDocumentComment.Summary)}</p>");
         if (item.XmlDocumentComment.Parameters != null && item.XmlDocumentComment.Parameters.Count > 0)
         {
             sb.Append("<h3>Parameter:</h3><p><ul>");
             foreach ((string k, string v) in item.XmlDocumentComment.Parameters)
             {
                 sb.Append($"<li>{MarkdownCodeQuote(k.Trim())} - {Regex.Replace(v.Trim(), @"\r\n?|\n", " ")}</li>");
             }
             sb.Append("</ul></p>");
         }
         if (!string.IsNullOrWhiteSpace(item.XmlDocumentComment.Remarks))
         {
             sb.AppendLine($"<h3>Remarks:</h3><p>{Beautifier.ReplaceLinks(item.XmlDocumentComment.Remarks)}</p>");
         }
         sb.AppendLine("<hr /></details>");
     }
     sb.AppendLine();
 }
示例#2
0
 public MarkdownableType(Type type, ILookup <string, XmlDocumentComment> commentLookup, ReferencedModelContainer referencedModelContainer)
 {
     _type                     = type;
     _commentLookup            = commentLookup;
     _markdownableTypeName     = new MarkdownableTypeName(_type);
     _beautifier               = new Beautifier(_commentLookup, referencedModelContainer);
     _referencedModelContainer = referencedModelContainer;
 }
示例#3
0
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            mb.HeaderWithCode(2, Beautifier.BeautifyType(type, false));
            mb.AppendLine();

            var desc = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? "";

            if (desc != "")
            {
                mb.AppendLine(desc);
            }
            {
                var sb = new StringBuilder();

                var stat = (type.IsAbstract && type.IsSealed) ? "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}{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());
            }

            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, "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.ToMarkdownMethodInfo(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());
        }
        public override string ToString()
        {
            MarkdownBuilder mb = new MarkdownBuilder();

            mb.HeaderWithCode(1, Beautifier.BeautifyType(type));
            mb.AppendLine();

            string desc = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ??
                          "";

            if (desc != "")
            {
                mb.AppendLine(desc);
            }
            {
                StringBuilder sb = new StringBuilder();

                string stat = type.IsAbstract && type.IsSealed ? "static " : "";
                string abst = type.IsAbstract && !type.IsInterface && !type.IsSealed ? "abstract " : "";
                string classOrStructOrEnumOrInterface = type.IsInterface
                    ? "interface"
                    : type.IsEnum
                        ? "enum"
                        : type.IsValueType
                            ? "struct"
                            : "class";

                sb.AppendLine(
                    $"public {stat}{abst}{classOrStructOrEnumOrInterface} {Beautifier.BeautifyType(type, true)}");
                string 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());
            }

            mb.AppendLine();

            if (type.IsEnum)
            {
                Type 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, x => x.Value.ToString(), x => x.Name, x => x.Name, (info, comment) => true);
            }
            else
            {
                BuildTable(
                    mb, "Constructors", GetConstructors(type),
                    x => x.Name, x => "#ctor", Beautifier.ToMarkdownConstructorInfo, (info, comment) =>
                {
                    ParameterInfo[] param = info.GetParameters();
                    return(param.Length == comment.Parameters.Count && param.All(
                               p =>
                    {
                        return comment.Parameters.ContainsKey(p.Name);
                    }));
                });
                BuildTable(
                    mb, "Fields", GetFields(type),
                    x => Beautifier.BeautifyType(x.FieldType),
                    x => x.Name, x => x.Name, (info, comment) => true);
                BuildTable(
                    mb, "Properties", GetProperties(type),
                    x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name, (info, comment) => true);
                BuildTable(
                    mb, "Events", GetEvents(type),
                    x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name,
                    (info, comment) => true);
                BuildTable(
                    mb, "Methods", GetMethods(type),
                    x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, Beautifier.ToMarkdownMethodInfo,
                    (info, comment) =>
                {
                    ParameterInfo[] param = info.GetParameters();
                    return(param.Length == comment.Parameters.Count && param.All(
                               p =>
                    {
                        return comment.Parameters.ContainsKey(p.Name);
                    }));
                });
                BuildTable(
                    mb, "Static Fields", GetStaticFields(type),
                    x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name, (info, comment) => true);
                BuildTable(
                    mb, "Static Properties", GetStaticProperties(type),
                    x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name, (info, comment) => true);
                BuildTable(
                    mb, "Static Methods", GetStaticMethods(type),
                    x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, Beautifier.ToMarkdownMethodInfo,
                    (info, comment) =>
                {
                    ParameterInfo[] param = info.GetParameters();
                    return(param.Length == comment.Parameters.Count && param.All(
                               p =>
                    {
                        return comment.Parameters.ContainsKey(p.Name);
                    }));
                });
                BuildTable(
                    mb, "Static Events", GetStaticEvents(type),
                    x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name,
                    (info, comment) => true);
            }

            return(mb.ToString());
        }