private string ParameterInfo(TypeScriptParameter param)
        {
            var result = param.Name + ": " + param.Type.Format(_lib);

            if (param.IsOptional)
            {
                result += ", " + MarkdownBuilder.MarkdownItalic("Optional") + " ";
            }
            else if (param.IsRest)
            {
                result += ", " + MarkdownBuilder.MarkdownItalic("Rest") + " ";
            }
            else if (param.DefaultValue != null)
            {
                result += ", " + MarkdownBuilder.MarkdownItalic("Default value") + " = " + MarkdownBuilder.MarkdownCodeQuote(param.DefaultValue);;
            }

            return(result);
        }
        private string BuildContent(TypeScriptEnumeration @enum)
        {
            var mb = new MarkdownBuilder();

            mb.AppendLine(@enum.Comment?.ShortText ?? "");
            mb.AppendLine();

            BuildExample(mb, @enum.Comment);


            mb.Header(3, "Enum");

            var headers = new string[] { "Name", "Value", "Description" };
            var data    = @enum.Members.Select(m => new string[] { m.Name, MarkdownBuilder.MarkdownCodeQuote(m.DefaultValue), m.Comment?.ShortText ?? "" });

            mb.Table(headers, data);

            return(mb.ToString());
        }
        private string BuildContent(TypeScriptInterface @interface, bool extension = false, string articleUrl = null)
        {
            var mb = new MarkdownBuilder();

            if (!string.IsNullOrEmpty(@interface.Comment?.ShortText))
            {
                mb.AppendLine(@interface.Comment.ShortText);
                mb.AppendLine();
            }

            BuildExample(mb, @interface.Comment);

            if (!extension)
            {
                BuildExtendedTypes(mb, @interface);
            }

            BuildIndex(mb, @interface, extension, articleUrl);

            if (@interface.Properties.Any())
            {
                mb.Header(2, "Properties");
                mb.AppendSeparateLine();
                foreach (var property in @interface.Properties)
                {
                    BuildContent(mb, property);
                }
            }


            if (@interface.Methods.Any())
            {
                mb.Header(2, "Methods");
                mb.AppendSeparateLine();
                foreach (var method in @interface.Methods)
                {
                    BuildContent(mb, method);
                }
            }

            return(mb.ToString());
        }
        private void BuildIndex(MarkdownBuilder mb, TypeScriptInterface @interface, bool extension, string articleUrl)
        {
            var path = @interface.GetPath().MakeUriFromString();

            if (extension)
            {
                path = @interface.Module.Module.GetPath().MakeUriFromString();
                if (!string.IsNullOrEmpty(articleUrl))
                {
                    path = path.CombineWithUri(articleUrl);
                }
            }

            mb.Header(2, "Index");
            if (@interface.Properties.Any())
            {
                mb.HeaderWithLink(3, "Properties", CombineWithRootUrl(path.CombineWithUri("#properties-1")));

                foreach (var property in @interface.Properties)
                {
                    mb.ListLink(property.Name, CombineWithRootUrl(path.CombineWithUri("#" + property.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (@interface.Methods.Any())
            {
                mb.HeaderWithLink(3, "Methods", CombineWithRootUrl(path.CombineWithUri("#methods-1")));
                foreach (var method in @interface.Methods)
                {
                    mb.ListLink(method.Name, CombineWithRootUrl(path.CombineWithUri("#" + method.Name.MakeUriFromString())));
                }
                mb.AppendLine();
            }

            mb.AppendLine();
            mb.AppendLine();
        }
Beispiel #5
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());
        }
Beispiel #6
0
 public string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown)
 {
     return($"● {Name}:{Type.Format(lib)}{((DefaultValue != null) ? " = " + MarkdownBuilder.MarkdownCodeQuote(DefaultValue) : "")}");
 }
Beispiel #7
0
 public override string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown)
 {
     return(MarkdownBuilder.MarkdownCodeQuote("\"" + Value + "\""));
 }
Beispiel #8
0
 public virtual string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown)
 {
     return(MarkdownBuilder.MarkdownCodeQuote(Name));
 }
        private void BuildIndex(MarkdownBuilder mb, TypeScriptClass @class)
        {
            var publicMethods    = @class.Methods.Where(m => !m.IsStatic && !m.IsPrivate && !m.IsProtected).ToList();
            var protectedMethods = @class.Methods.Where(m => m.IsProtected).ToList();
            var staticMethods    = @class.Methods.Where(m => m.IsStatic && !m.IsPrivate).ToList();


            var publicProperties    = @class.Properties.Where(p => !p.IsStatic && !p.IsPrivate && !p.IsProtected).ToList();
            var protectedProperties = @class.Properties.Where(p => p.IsProtected).ToList();
            var staticProperties    = @class.Properties.Where(p => p.IsStatic && !p.IsPrivate).ToList();

            var publicAccessors    = @class.Accessors.Where(m => !m.IsPrivate && !m.IsProtected).ToList();
            var protectedAccessors = @class.Accessors.Where(p => p.IsProtected).ToList();

            var path = @class.GetPath().MakeUriFromString();

            //Index region
            mb.Header(2, "Index");
            if (@class.Constructor != null)
            {
                mb.HeaderWithLink(3, "Constructors", CombineWithRootUrl(path.CombineWithUri("#constructors-1")));
                mb.ListLink("constructor", CombineWithRootUrl(path.CombineWithUri("#constructor")));

                mb.AppendLine();
            }

            if (publicProperties.Any())
            {
                mb.HeaderWithLink(3, "Public Properties", CombineWithRootUrl(path.CombineWithUri("#public-properties-1")));

                foreach (var property in publicProperties)
                {
                    mb.ListLink(property.Name, CombineWithRootUrl(path.CombineWithUri("#" + property.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (protectedProperties.Any())
            {
                mb.HeaderWithLink(3, "Protected Properties", CombineWithRootUrl(path.CombineWithUri("#protected-properties-1")));

                foreach (var property in protectedProperties)
                {
                    mb.ListLink(property.Name, CombineWithRootUrl(path.CombineWithUri("#" + property.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (staticProperties.Any())
            {
                mb.HeaderWithLink(3, "Static Properties", CombineWithRootUrl(path.CombineWithUri("#static-properties-1")));

                foreach (var property in staticProperties)
                {
                    mb.ListLink(property.Name, CombineWithRootUrl(path.CombineWithUri("#" + property.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (publicAccessors.Any())
            {
                mb.HeaderWithLink(3, "Public Accessors", CombineWithRootUrl(path.CombineWithUri("#public-accessors-1")));

                foreach (var accessor in publicAccessors)
                {
                    mb.ListLink(accessor.Name, CombineWithRootUrl(path.CombineWithUri("#" + accessor.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (protectedAccessors.Any())
            {
                mb.HeaderWithLink(3, "Protected Accessors", CombineWithRootUrl(path.CombineWithUri("#protected-accessors-1")));

                foreach (var accessor in protectedAccessors)
                {
                    mb.ListLink(accessor.Name, CombineWithRootUrl(path.CombineWithUri("#" + accessor.Name.MakeUriFromString())));
                }

                mb.AppendLine();
            }

            if (publicMethods.Any())
            {
                mb.HeaderWithLink(3, "Public Methods", CombineWithRootUrl(path.CombineWithUri("#public-methods-1")));
                foreach (var method in publicMethods)
                {
                    mb.ListLink(method.Name, CombineWithRootUrl(path.CombineWithUri("#" + method.Name.MakeUriFromString())));
                }
                mb.AppendLine();
            }

            if (protectedMethods.Any())
            {
                mb.HeaderWithLink(3, "Protected Methods", CombineWithRootUrl(path.CombineWithUri("#protected-methods-1")));
                foreach (var method in protectedMethods)
                {
                    mb.ListLink(method.Name, CombineWithRootUrl(path.CombineWithUri("#" + method.Name.MakeUriFromString())));
                }
                mb.AppendLine();
            }

            if (staticMethods.Any())
            {
                mb.HeaderWithLink(3, "Static Methods", CombineWithRootUrl(path.CombineWithUri("#static-methods-1")));
                foreach (var property in staticMethods)
                {
                    mb.ListLink(property.Name, CombineWithRootUrl(path.CombineWithUri("#" + property.Name.MakeUriFromString())));
                }
                mb.AppendLine();
            }
            mb.AppendLine();
        }
Beispiel #10
0
        private string BuildContent(TypeScriptClass @class)
        {
            var mb = new MarkdownBuilder();

            if (!string.IsNullOrEmpty(@class.Comment?.ShortText))
            {
                mb.AppendLine(@class.Comment.ShortText);
                mb.AppendLine();
            }

            BuildExample(mb, @class.Comment);

            BuildImplementedTypes(mb, @class);
            BuildExtendedTypes(mb, @class);

            BuildIndex(mb, @class);

            if (@class.Constructor != null)
            {
                mb.Header(2, "Constructors");
                mb.AppendSeparateLine();
                mb.Header(4, "constructor");
                mb.AppendLine();

                if (!string.IsNullOrEmpty(@class.Constructor.Signatures.First().Comment?.ShortText))
                {
                    mb.AppendLine(@class.Constructor.Signatures.First().Comment.ShortText);
                }

                foreach (var signature in @class.Constructor.Signatures)
                {
                    mb.AppendLine("⊕ " + signature.Format(_lib));
                    mb.AppendLine();
                }


                BuildParameters(mb, @class.Constructor.Signatures.Last().Parameters);

                BuildExample(mb, @class.Constructor.Signatures.First().Comment);

                mb.AppendSeparateLine();
            }

            mb.AppendLine();


            var publicMethods    = @class.Methods.Where(m => !m.IsStatic && !m.IsPrivate && !m.IsProtected).ToList();
            var protectedMethods = @class.Methods.Where(m => m.IsProtected).ToList();
            var staticMethods    = @class.Methods.Where(m => m.IsStatic && !m.IsPrivate).ToList();


            var publicProperties    = @class.Properties.Where(p => !p.IsStatic && !p.IsPrivate && !p.IsProtected).ToList();
            var protectedProperties = @class.Properties.Where(p => p.IsProtected).ToList();
            var staticProperties    = @class.Properties.Where(p => p.IsStatic && !p.IsPrivate).ToList();

            var publicAccessors   = @class.Accessors.Where(a => !a.IsPrivate && !a.IsProtected).ToList();
            var protectedAccesors = @class.Accessors.Where(a => a.IsProtected).ToList();

            if (publicProperties.Any())
            {
                mb.Header(2, "Public Properties");
                mb.AppendSeparateLine();
                foreach (var property in publicProperties)
                {
                    BuildContent(mb, property);
                }
            }

            if (protectedProperties.Any())
            {
                mb.Header(2, "Protected Properties");
                mb.AppendSeparateLine();
                foreach (var property in protectedProperties)
                {
                    BuildContent(mb, property);
                }
            }

            if (staticProperties.Any())
            {
                mb.Header(2, "Static Properties");
                mb.AppendSeparateLine();
                foreach (var property in staticProperties)
                {
                    BuildContent(mb, property);
                }
            }

            if (publicAccessors.Any())
            {
                mb.Header(2, "Public Accessors");
                mb.AppendSeparateLine();
                foreach (var accessor in publicAccessors)
                {
                    BuildContent(mb, accessor);
                }
            }

            if (protectedAccesors.Any())
            {
                mb.Header(2, "Protected Accessors");
                mb.AppendSeparateLine();
                foreach (var accessor in protectedAccesors)
                {
                    BuildContent(mb, accessor);
                }
            }

            if (publicMethods.Any())
            {
                mb.Header(2, "Public Methods");
                mb.AppendSeparateLine();
                foreach (var method in publicMethods)
                {
                    BuildContent(mb, method);
                }
            }

            if (protectedMethods.Any())
            {
                mb.Header(2, "Protected Methods");
                mb.AppendSeparateLine();
                foreach (var method in protectedMethods)
                {
                    BuildContent(mb, method);
                }
            }

            if (staticMethods.Any())
            {
                mb.Header(2, "Static Methods");
                mb.AppendSeparateLine();
                foreach (var method in staticMethods)
                {
                    BuildContent(mb, method);
                }
            }

            return(mb.ToString());
        }
Beispiel #11
0
        public static string ToMarkdownTypeReference(CSharpLibrary lib, TypeReference t, bool isParam = false)
        {
            if (t == null)
            {
                return("");
            }
            if (t.FullName == "System.Void")
            {
                return("`void`");
            }
            if (t.FullName == "System.Object")
            {
                return("`object`");
            }
            if (t.FullName == "System.Boolean")
            {
                return("`bool`");
            }
            if (t.FullName == "System.String")
            {
                return("`string`");
            }
            if (t.FullName == "System.Int32")
            {
                return("`int`");
            }
            if (t.FullName == "System.Int64")
            {
                return("`long`");
            }
            if (t.FullName == "System.Double")
            {
                return("`double`");
            }

            var hasMdType = lib.Types.TryGetValue(t.FullName, out var mdType);

            string name;

            if (!t.IsGenericInstance && !t.HasGenericParameters)
            {
                name = (t.IsNested && !isParam) ? $"{t.DeclaringType.Name}.{t.Name}" : t.Name;
                if (hasMdType)
                {
                    return(MarkdownBuilder.MarkdownUrl(name, mdType.GetPath()));
                }

                return(MarkdownBuilder.MarkdownCodeQuote(name));
            }

            string innerFormat = "";

            if (t is GenericInstanceType genType)
            {
                var args = genType.GenericArguments.ToArray();
                innerFormat = string.Join(", ", args.Select(x => ToMarkdownTypeReference(lib, x, isParam: true)));
            }
            else
            {
                innerFormat = string.Join(", ", t.GenericParameters.Select(x => x.Name));
            }

            name = Regex.Replace(t.Name, @"`.+$?", "");
            if (hasMdType)
            {
                name = MarkdownBuilder.MarkdownUrl(name, mdType.GetPath());
            }
            else
            {
                name = MarkdownBuilder.MarkdownCodeQuote(name);
            }

            return(name + "<" + innerFormat + ">");
        }