void BuildTable <T>(MarkdownBuilder mb, string label, T[] array, IEnumerable <XmlDocumentComment> docs, Func <T, string> getTypeNameFunc, Func <T, string> getFieldNameFunc, Func <T, string> getFinalNameFunc) { if (array.Any()) { mb.AppendLine("### " + label); mb.AppendLine(); string[] head = (this._type.IsEnum) ? new[] { "Value", "Name", "Description" } : new[] { "Type", "Name", "Description" }; // IEnumerable<T> seq = array; if (!this._type.IsEnum) { array = array.OrderBy(x => getFieldNameFunc(x)).ToArray(); } var data = array.Select(item2 => { var summary = docs.FirstOrDefault(x => x.MemberName == getFieldNameFunc(item2))?.Summary ?? ""; var typeName = ""; try { typeName = getTypeNameFunc(item2); } catch { typeName = "[Unknown type]"; } return(new[] { MarkdownBuilder.MarkdownCodeQuote(typeName), getFinalNameFunc(item2), summary }); }); mb.Table(head, data); mb.AppendLine(); } }
public override string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown) { if (Signature != null) { return($"({string.Join(", ", Signature.Parameters.Select(p => p.Format(lib, mode)))}) => {Signature.Type.Format(lib, mode)}"); } return(MarkdownBuilder.MarkdownCodeQuote("any")); }
public override string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown) { var path = lib.FindPathToType(Name); var name = path != null?MarkdownBuilder.MarkdownUrl(Name, path) : MarkdownBuilder.MarkdownCodeQuote(Name); if (TypeArguments.Any()) { name += "<" + string.Join(",", TypeArguments.Select(t => t.Format(lib, mode))) + ">"; } return(name); }
private void BuildContent(MarkdownBuilder mb, TypeScriptVariable variable) { mb.Header(3, MarkdownBuilder.MarkdownCodeQuote(variable.IsConst ? "const" : variable.IsLet ? "let" : "var") + " " + variable.Name); mb.AppendLine(); if (!string.IsNullOrEmpty(variable.Comment?.ShortText)) { mb.AppendLine(variable.Comment.ShortText); mb.AppendLine(); } mb.AppendLine(variable.Format(_lib)); mb.AppendLine(); BuildExample(mb, variable.Comment); mb.AppendSeparateLine(); }
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()); }
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()); }
public string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown) { return($"● {Name}:{Type.Format(lib)}{((DefaultValue != null) ? " = " + MarkdownBuilder.MarkdownCodeQuote(DefaultValue) : "")}"); }
public override string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown) { return(MarkdownBuilder.MarkdownCodeQuote("\"" + Value + "\"")); }
public virtual string Format(ITypeScriptLibrary lib, FormatMode mode = FormatMode.Markdown) { return(MarkdownBuilder.MarkdownCodeQuote(Name)); }
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); }
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 + ">"); }