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(); } }
private void BuildIndex(MarkdownBuilder mb, TypeScriptInterface @interface) { var path = @interface.GetPath().MakeUriFromString(); 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(); }
private void BuildExtendedTypes(MarkdownBuilder mb, ITypeScriptExtended ex) { if (ex.ExtendedTypes.Any()) { mb.Header(2, "Extends"); mb.AppendLine(string.Join(", ", ex.ExtendedTypes.Select(t => t.Format(_lib)))); mb.AppendLine(); } }
private void BuildImplementedTypes(MarkdownBuilder mb, ITypeScriptImplemented im) { if (im.ImplementedTypes.Any()) { mb.Header(2, "Implements"); mb.AppendLine(string.Join(", ", im.ImplementedTypes.Select(t => t.Format(_lib)))); mb.AppendLine(); } }
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(); }
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()); }
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(); } }
private void BuildParameters(MarkdownBuilder mb, List <TypeScriptParameter> parameters) { if (parameters.Count > 0) { mb.Header(4, "Parameters:"); foreach (var param in parameters) { var paramInfo = ParameterInfo(param); if (param.Comment != null) { if (!string.IsNullOrEmpty(param.Comment.ShortText)) { paramInfo += " - " + param.Comment.ShortText; } else if (!string.IsNullOrEmpty(param.Comment.Text)) { paramInfo += " - " + param.Comment.Text; } } mb.List(paramInfo); } mb.AppendLine(); } }
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 void BuildContent(MarkdownBuilder mb, TypeScriptProperty property) { mb.Header(3, property.Name); mb.AppendLine(); if (!string.IsNullOrEmpty(property.Comment?.ShortText)) { mb.AppendLine(property.Comment.ShortText); mb.AppendLine(); } mb.AppendLine(property.Format(_lib)); BuildExample(mb, property.Comment); mb.AppendSeparateLine(); }
private string BuildReleaseNotes(ProjectSettings project, Dictionary <string, List <CommitWithType> > commitGroups) { var mb = new MarkdownBuilder(); if (!project.SkipVersionHeading) { var title = project.TitleTemplate .Replace("${VersionNum}", Version ?? project.NewVersion); mb.Header(2, title); mb.AppendLine(); } if (!string.IsNullOrEmpty(project.DateItemTemplate)) { mb.AppendLine(project.DateItemTemplate.Replace("${ReleasedDate}", DateTime.UtcNow.ToString("yyyy-MM-dd"))); } mb.AppendLine(); if (commitGroups.TryGetValue("NEW", out var newCommits)) { foreach (var commit in newCommits) { WriteCommitWithType(mb, project, commit, "New"); } } if (commitGroups.TryGetValue("UPD", out var updateCommits)) { foreach (var commit in updateCommits) { WriteCommitWithType(mb, project, commit, "Upd"); } } if (commitGroups.TryGetValue("FIX", out var fixCommits)) { foreach (var commit in fixCommits) { WriteCommitWithType(mb, project, commit, "Fix"); } } return(mb.ToString()); }
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 void BuildIndex(MarkdownBuilder mb, List <TypeScriptVariable> variables) { mb.Header(2, "Index"); foreach (var variable in variables) { mb.ListLink(variable.Name, CombineWithRootUrl(variable.GetPath().MakeUriFromString().CombineWithUri("#" + variable.Name.MakeUriFromString()))); } mb.AppendLine(); }
private void BuildIndex(MarkdownBuilder mb, List <TypeScriptFunction> functions) { mb.Header(2, "Index"); foreach (var function in functions) { mb.ListLink(function.Name, CombineWithRootUrl(function.GetPath().MakeUriFromString().CombineWithUri("#" + function.Name.MakeUriFromString()))); } mb.AppendLine(); }
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 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(); }
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()); }
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(); }
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()); }