Example #1
0
 private void BuildExample(MarkdownBuilder mb, TypeScriptComment comment)
 {
     if (comment != null)
     {
         if (comment.Tags.TryGetValue("example", out var text))
         {
             mb.Header(4, "Example: ");
             mb.Code("typescript", text);
         }
     }
 }
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            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} {CSharpBeautifier.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 => CSharpBeautifier.BeautifyType(x)));
                if (impl != "")
                {
                    sb.AppendLine("    : " + impl);
                }

                mb.Code("csharp", sb.ToString());
            }

            mb.AppendLine();

            if (_type.IsEnum)
            {
                var enums = Enum.GetNames(_type)
                            .Select(x => new { Name = x, Value = ((Int32)Enum.Parse(_type, x)) })
                            .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 => CSharpBeautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
                BuildTable(mb, "Methods", GetMethods(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(x));
                BuildTable(mb, "Static Fields", GetStaticFields(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(x));
                BuildTable(mb, "Static Events", GetStaticEvents(), CommentLookUp[_type.FullName], x => CSharpBeautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }
Example #3
0
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            var desc = Comments.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} {CSharpBeautifier.BeautifyType(_type, isFull: true)}");
                var impl = string.Join(", ", new[] { _type.BaseType }.Concat(_type.Interfaces.Select(x => x.InterfaceType))
                                       .Where(x => x != null && x.FullName != "System.Object" && x.FullName != "System.ValueType")
                                       .Select(x => CSharpBeautifier.BeautifyType(x)));
                if (impl != "")
                {
                    sb.AppendLine("    : " + impl);
                }

                mb.Code("csharp", sb.ToString());
            }

            if (_package != null)
            {
                mb.Append("Package: ");
                mb.CodeQuote(_package.Name);

                if (TargetFrameworks.Any())
                {
                    mb.Append(" (targets: ");
                    mb.Append(string.Join(", ", TargetFrameworks.Select(tfm => MarkdownBuilder.MarkdownCodeQuote(tfm))));
                    mb.Append(")");
                }

                mb.AppendLine();
                mb.AppendLine();
            }


            mb.Append("Assembly: ");
            mb.CodeQuote($"{this.AssymblyName}.dll");
            mb.AppendLine();
            mb.AppendLine();


            if (_type.IsEnum)
            {
                var enums = _type.Fields
                            .Where(x => x.Name != "value__")
                            .Select(x => new { Name = x.Name, Value = Convert.ToInt64(x.Constant) })
                            .OrderBy(x => x.Value)
                            .ToArray();

                BuildTable(mb, "Enum", enums, Comments, x => MarkdownBuilder.MarkdownCodeQuote(x.Value.ToString()), x => x.Name, x => x.Name);
            }
            else
            {
                BuildTable(mb, "Constructors", GetConstructors(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Fields", GetFields(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.EventType), x => x.Name, x => x.Name);
                BuildTable(mb, "Methods", GetMethods(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Static Fields", GetStaticFields(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.ReturnType), x => x.Name, x => CSharpBeautifier.ToMarkdownMethodInfo(_library, x));
                BuildTable(mb, "Static Events", GetStaticEvents(), Comments, x => CSharpBeautifier.ToMarkdownTypeReference(_library, x.EventType), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }