public static void BuildNamespaceLinks(this IMarkdownItem item, string namespaceValue, MarkdownBuilder mb) { var namespaceItems = namespaceValue.Split('.'); string globalNamespace = ""; mb.Append("Namespace: "); foreach (var namespaceItem in namespaceItems) { if (!String.IsNullOrEmpty(globalNamespace)) { globalNamespace += "."; mb.Append(" > "); } globalNamespace = globalNamespace + namespaceItem; if (item.Project.TryGetValue(new TypeWrapper(globalNamespace), out IMarkdownItem foundItem)) { mb.Link(namespaceItem, item.To(foundItem)); } else { mb.Link(namespaceItem, ""); } } mb.AppendLine().AppendLine(); }
public static string GetLink(this IMarkdownItem currentItem, TypeWrapper info) { if (currentItem.Project.TryGetValue(info, out IMarkdownItem lookupItem)) { return(currentItem.To(lookupItem)); } else if (info.FullName.StartsWith("System") || info.FullName.StartsWith("Microsoft")) { return("https://docs.microsoft.com/en-us/dotnet/api/" + Cleaner.CleanName(info.FullName, true, false)); } return(null); }
/// <summary> /// Create a constructor with links and parameters /// </summary> /// <param name="currentItem">The current location to create this Constructor name with links</param> /// <param name="constructor">The constructor to clean up</param> /// <param name="useFullName">Use full name of the constructor</param> /// <param name="useParameterNames">Use parameter names if set to false only type will be shown</param> /// <returns>The markdown string</returns> public static string CreateFullConstructorsWithLinks(IMarkdownItem currentItem, MarkdownConstructor constructor, bool useFullName, bool useParameterNames) { var parameters = constructor.InternalItem.GetParameters(); MarkdownBuilder mb = new MarkdownBuilder(); string name = useFullName ? CleanFullName(constructor.ParentType.InternalType, false, false) : CleanName(constructor.ParentType.Name, false, false); if (constructor.FileName != null) { mb.Link(name, currentItem.To(constructor)); } else { mb.Append(name); } mb.Append(" ("); if (parameters.Length > 0) { StringBuilder sb = new StringBuilder(); for (var i = 0; i < parameters.Length; i++) { var type = parameters[i].ParameterType; var link = CreateFullTypeWithLinks(currentItem, type, useFullName, true); sb.Append(link); if (useParameterNames) { sb.Append($" {parameters[i].Name}"); } if (i + 1 != parameters.Length) { sb.Append(", "); } } mb.Append(sb.ToString()); } mb.Append(")"); return(mb.ToString()); }
/// <summary> /// Create a full parameter name with links /// </summary> /// <param name="currentItem">The current markdown item with the property to be rendered</param> /// <param name="property">The markdown property</param> /// <param name="useFullName">Determines if the fullName of Markdown property should be used</param> /// <param name="useParameterNames">Determines if parameter names should be shown on property</param> /// <returns>Returns the full parameter name with links rendered in markdown</returns> public static string CreateFullParameterWithLinks(IMarkdownItem currentItem, MarkdownProperty property, bool useFullName, bool useParameterNames) { var fullParameterName = property.InternalItem.ToString(); MarkdownBuilder mb = new MarkdownBuilder(); if (property.FileName != null) { mb.Link(property.Name, currentItem.To(property)); } else { mb.Append(property.Name); } var parts = fullParameterName.Split('[', ']'); var index = property.InternalItem.GetPropertyKeyType(); if (index.Key != null) { mb.Append(" [ "); var link = CreateFullTypeWithLinks(currentItem, index.Key, useFullName, true); mb.Append(link); if (useParameterNames) { mb.Append($" {index.Name}"); } mb.Append(" ]"); } return(mb.ToString()); }
/// <summary> /// Cleans a method and adds the appropiate links /// </summary> /// <param name="currentItem">The current markdown item containing the method to be cleaned</param> /// <param name="method">The method to be cleaned</param> /// <param name="useFullName">Determine if full name of method should be shown</param> /// <param name="useParameterNames">Determines if parameter names should be shown</param> /// <param name="parameterList">Determines if parameter names should be listed vertically</param> /// <returns>The cleaned string</returns> public static string CreateFullMethodWithLinks(IMarkdownItem currentItem, MarkdownMethod method, bool useFullName, bool useParameterNames, bool parameterList) { var parameters = method.InternalItem.GetParameters(); MarkdownBuilder mb = new MarkdownBuilder(); if (!parameterList) { if (method.FileName != null) { mb.Link(method.Name, currentItem.To(method)); } else { mb.Append(method.Name); } mb.Append(" ("); } if (parameters.Length > 0) { StringBuilder sb = new StringBuilder(); for (var i = 0; i < parameters.Length; i++) { var type = parameters[i].ParameterType; var link = CreateFullTypeWithLinks(currentItem, type, useFullName, true); if (link.IndexOf('&') > 0) { link = link.Replace("&", ""); sb.Append("out "); } if (!parameterList) { sb.Append(link); if (useParameterNames) { sb.Append($" {parameters[i].Name}"); } } else { if (useParameterNames) { sb.Append($" {parameters[i].Name}"); } sb.Append(link); } if (!parameterList) { if (i + 1 != parameters.Length) { sb.Append(", "); } } else { if (i + 1 != parameters.Length) { sb.Append("<br>"); } } } mb.Append(sb.ToString()); } if (!parameterList) { mb.Append(")"); } return(mb.ToString()); }
public static string GetNameOrNameLink(this IMarkdownItem currentType, Type targetType, bool useFullName, bool specialText) { MarkdownBuilder tempMB = new MarkdownBuilder(); if (targetType == null) { return(""); } if (targetType == typeof(void)) { return("[Void]" + "(https://docs.microsoft.com/en-us/dotnet/api/System.Void)"); } if (targetType.FullName == null && targetType.Name == null) { return(""); } // exceptions if (targetType.ToString().Equals("System.Collections.Generic.IEnumerable`1[T]") || targetType.ToString().Equals("System.Collections.Generic.IEnumerable`1[P]")) { return("[IEnumerable]" + "(https://docs.microsoft.com/en-us/dotnet/api/System.Collections.Ienumerable)"); } if (targetType.ToString().Contains("System.Func`3")) { return("[Func]" + "(https://docs.microsoft.com/en-us/dotnet/api/System.Func-3)"); } string name = targetType.Name; string fullName = targetType.ToString(); if (useFullName) { name = Cleaner.CleanName(fullName, false, specialText); } else { name = Cleaner.CleanName(targetType.Name.GetBaseName(), false, specialText); } var link = currentType.GetLink(new TypeWrapper(targetType)); if (link != null) { tempMB.Link(name, link); } else { tempMB.Link(name, currentType.To(currentType)); } if (targetType.IsArray) { tempMB.Append("[]"); } return(tempMB.ToString()); }