Example #1
0
        private void BuildContent(MarkdownBuilder mb, TypeScriptFunction function)
        {
            mb.Header(4, function.Name);
            mb.AppendLine();
            if (!string.IsNullOrEmpty(function.Signatures.First().Comment?.ShortText))
            {
                mb.AppendLine(function.Signatures.First().Comment.ShortText);
                mb.AppendLine();
            }

            foreach (var signature in function.Signatures)
            {
                mb.AppendLine("▸ " + signature.Format(_lib));

                mb.AppendLine();

                BuildParameters(mb, signature.Parameters);

                mb.AppendLine();

                mb.Append($"**Returns** " + signature.Type.Format(_lib));
                if (!string.IsNullOrEmpty(signature.Comment?.Returns))
                {
                    mb.Append(" - " + signature.Comment.Returns);
                }

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

            BuildExample(mb, function.Signatures.First().Comment);

            mb.AppendLine();
            mb.AppendSeparateLine();
        }
        private void BuildContent(MarkdownBuilder mb, TypeScriptMethod method)
        {
            mb.Header(3, method.Name);

            if (!string.IsNullOrEmpty(method.Signature.Comment?.ShortText))
            {
                mb.AppendLine(method.Signature.Comment.ShortText);
                mb.AppendLine();
            }

            mb.AppendLine(method.Format(_lib));
            mb.AppendLine();

            BuildParameters(mb, method.Signature.Parameters);

            mb.AppendLine();
            mb.Append($"**Returns** " + method.Signature.Type.Format(_lib));
            if (!string.IsNullOrEmpty(method.Signature.Comment?.Returns))
            {
                mb.Append(" - " + method.Signature.Comment.Returns);
            }
            mb.AppendLine();

            BuildExample(mb, method.Signature.Comment);

            mb.AppendSeparateLine();
        }
Example #3
0
        private void BuildContent(MarkdownBuilder mb, TypeScriptAccessor accessor)
        {
            mb.Header(3, accessor.Name);

            if (accessor.GetSignature != null)
            {
                mb.AppendLine("⇄ " + accessor.GetSignature.Format(_lib));

                mb.AppendLine();

                BuildParameters(mb, accessor.GetSignature.Parameters);

                mb.AppendLine();

                mb.Append($"**Returns** " + accessor.GetSignature.Type.Format(_lib));
                if (!string.IsNullOrEmpty(accessor.GetSignature.Comment?.Returns))
                {
                    mb.Append(" - " + accessor.GetSignature.Comment.Returns);
                }

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

                mb.AppendSeparateLine();
            }

            if (accessor.SetSignature != null)
            {
                mb.AppendLine("⇄ " + accessor.SetSignature.Format(_lib));

                mb.AppendLine();

                BuildParameters(mb, accessor.SetSignature.Parameters);

                mb.AppendLine();

                mb.Append($"**Returns** " + accessor.SetSignature.Type.Format(_lib));
                if (!string.IsNullOrEmpty(accessor.SetSignature.Comment?.Returns))
                {
                    mb.Append(" - " + accessor.SetSignature.Comment.Returns);
                }

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

                mb.AppendSeparateLine();
            }
        }
Example #4
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());
        }