void LoadMembers() { try { using (var s = entry.Open()) { doc = XDocument.Load(s); var ns = doc.Root.Name.Namespace; var asm = doc.Root.Element(ns + "assembly"); if (asm == null) { Error = "Not an docs files"; return; } AssemblyName = asm.Value.Trim(); // System.Console.WriteLine(AssemblyName); foreach (var me in doc.Root.Element(ns + "members").Elements(ns + "member")) { var m = new MemberXmlDocs(me); // System.Console.WriteLine(m.Name); if (!string.IsNullOrEmpty(m.Name)) { members[m.Name] = m; } } } Error = ""; } catch (Exception ex) { // System.Console.WriteLine (ex); // if (doc != null) System.Console.WriteLine(doc); Error = ex.Message; } }
void WriteDocumentation(TextWriter w) { var members = typeDefinition.GetPublicMembers(); var isExtensionClass = typeDefinition.IsExtensionClass(); foreach (var m in members) { var xmlName = m.GetXmlName(); MemberXmlDocs mdocs = null; xmlDocs?.MemberDocs.TryGetValue(xmlName, out mdocs); w.WriteLine("<div class='member-code'>"); m.WritePrototypeHtml(w, framework: framework, linkToCode: true, isExtensionClass); w.WriteLine("</div>"); w.WriteLine("<p>"); if (mdocs != null) { var html = XmlToHtml(mdocs?.SummaryXml); if (ignoreSummaryTextRe.IsMatch(html)) { html = ""; } w.Write(html); } else { //w.WriteLine ("<b>"); //WriteEncodedHtml (xmlName, w); //w.WriteLine ("</b>"); } w.WriteLine("</p>"); } }
public PackageAssemblyXmlDocs(ZipArchiveEntry entry) { try { using (var s = entry.Open()) { doc = XDocument.Load(s); var ns = doc.Root.Name.Namespace; AssemblyName = doc.Root.Element(ns + "assembly").Value.Trim(); // System.Console.WriteLine(AssemblyName); foreach (var me in doc.Root.Element(ns + "members").Elements(ns + "member")) { var m = new MemberXmlDocs(me); // System.Console.WriteLine(m.Name); if (!string.IsNullOrEmpty(m.Name)) { MemberDocs[m.Name] = m; } } } Error = ""; } catch (Exception ex) { // System.Console.WriteLine (ex); // if (doc != null) System.Console.WriteLine(doc); Error = ex.Message; } }
public PackageAssemblyXmlLanguageDocs(ZipArchiveEntry entry) { LanguageCode = "en"; try { var path = entry.FullName; var pathParts = path.Split(pathSplitChars, StringSplitOptions.RemoveEmptyEntries); // lib/framework/language/file.xml // 0 1 2 3 if (pathParts.Length == 4) { LanguageCode = pathParts[2]; } } catch (Exception ex) { Console.WriteLine(ex); } try { using (var s = entry.Open()) { doc = XDocument.Load(s); var ns = doc.Root.Name.Namespace; var asm = doc.Root.Element(ns + "assembly"); if (asm == null) { Error = "Not an docs files"; return; } AssemblyName = asm.Value.Trim(); // System.Console.WriteLine(AssemblyName); foreach (var me in doc.Root.Element(ns + "members").Elements(ns + "member")) { var m = new MemberXmlDocs(me); // System.Console.WriteLine(m.Name); if (!string.IsNullOrEmpty(m.Name)) { MemberDocs[m.Name] = m; } } } Error = ""; } catch (Exception ex) { // System.Console.WriteLine (ex); // if (doc != null) System.Console.WriteLine(doc); Error = ex.Message; } }
public TypeDocumentation(TypeDefinition typeDefinition, PackageTargetFramework framework, PackageAssemblyXmlDocs xmlDocs, Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> decompiler, Lazy <ICSharpCode.Decompiler.CSharp.CSharpDecompiler> idecompiler, ICSharpCode.Decompiler.CSharp.OutputVisitor.CSharpFormattingOptions format, string languageCode) { this.xmlDocs = xmlDocs; this.languageCode = languageCode; this.typeDefinition = typeDefinition; this.framework = framework; this.decompiler = decompiler; this.idecompiler = idecompiler; this.format = format; SummaryHtml = ""; SummaryText = ""; DocumentationHtml = ""; if (xmlDocs != null) { var tn = typeDefinition.GetXmlName(); var ldocs = xmlDocs.GetLanguage(languageCode); if (ldocs.MemberDocs.TryGetValue(tn, out var td)) { MemberXmlDocs = td; SummaryHtml = XmlToHtml(td.SummaryXml); SummaryText = XmlToText(td.SummaryXml); if (ignoreSummaryTextRe.IsMatch(SummaryHtml)) { SummaryHtml = ""; SummaryText = ""; } } } var w = new StringWriter(); WriteDocumentation(w); DocumentationHtml = w.ToString(); }
public static string GetPrototypeHtml(this IMemberDefinition member, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode, bool inExtensionClass) { using (var w = new StringWriter()) { WritePrototypeHtml(member, w, framework, docs, linkToCode, inExtensionClass); return(w.ToString()); } }
public static void WritePrototypeHtml(this IMemberDefinition member, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode, bool inExtensionClass) { switch (member) { case FieldDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case MethodDefinition t: WritePrototypeHtml(t, w, framework, docs, linkToCode, inExtensionClass); break; case PropertyDefinition t: WritePrototypeHtml(t, w, framework, docs, linkToCode); break; case EventDefinition t: WritePrototypeHtml(t, w, framework, linkToCode); break; case TypeDefinition t: WritePrototypeHtml(t, w, framework, docs, linkToCode); break; default: throw new NotSupportedException(member.GetType() + " " + member.FullName); } }
public static void WritePrototypeHtml(this TypeDefinition member, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode) { if (member.IsNestedFamily || member.IsNestedFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic || member.IsNestedPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.IsSealed && member.IsAbstract) { w.Write("<span class=\"c-kw\">static</span> "); } else if (member.IsSealed && !member.IsEnum && !member.IsValueType) { w.Write("<span class=\"c-kw\">sealed</span> "); } else if (member.IsAbstract && !member.IsInterface) { w.Write("<span class=\"c-kw\">abstract</span> "); } if (member.IsEnum) { w.Write("<span class=\"c-kw\">enum</span> "); } else if (member.IsValueType) { w.Write("<span class=\"c-kw\">struct</span> "); } else if (member.IsInterface) { w.Write("<span class=\"c-kw\">interface</span> "); } else if (member.IsDelegate()) { w.Write("<span class=\"c-kw\">delegate</span> "); } else { w.Write("<span class=\"c-kw\">class</span> "); } var id = member.GetXmlName(); var name = member.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } var url = framework?.FindTypeUrl(member); if (url != null) { w.Write($"<a id=\"{id}\" href=\"{url}\" class=\"c-td\">"); WriteEncoded(name, w); w.Write("</a>"); } else { w.Write($"<span id=\"{id}\" class=\"c-td\">"); WriteEncoded(name, w); w.Write("</span>"); } if (member.HasGenericParameters) { WriteGenericParameterListHtml(member.GenericParameters, w, framework, docs); } var hier = ((!member.IsEnum && !member.IsValueType && member.BaseType != null && member.BaseType.FullName != "System.Object") ? new[] { member.BaseType } : new TypeReference[0]) .Concat(member.Interfaces.Select(x => x.InterfaceType)).ToList(); if (hier.Count > 0) { w.Write(" : "); var head = ""; foreach (var h in hier) { w.Write(head); WriteReferenceHtml(h, w, framework); head = ", "; } } if (member.HasGenericParameters) { WriteGenericConstraintsHtml(member.GenericParameters, w, framework); } }
public static void WritePrototypeHtml(this PropertyDefinition member, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode) { if (member.GetMethod != null && !member.DeclaringType.IsInterface) { if ((member.GetMethod.IsFamily || member.GetMethod.IsFamilyOrAssembly)) { w.Write("<span class=\"c-kw\">protected</span> "); } else if ((member.GetMethod.IsPublic)) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.GetMethod.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } else if (member.GetMethod.IsAbstract) { w.Write("<span class=\"c-kw\">abstract</span> "); } else if (member.GetMethod.IsVirtual) { if (member.GetMethod.IsReuseSlot) { w.Write("<span class=\"c-kw\">override</span> "); } else if (!member.GetMethod.IsFinal) { w.Write("<span class=\"c-kw\">virtual</span> "); } } } WriteReferenceHtml(member.PropertyType, w, framework); var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); if (member.GetMethod != null && member.GetMethod.Parameters.Count > 0) { w.Write($" <a {href} id=\"{id}\" class=\"c-pd\">this</a>["); var head = ""; foreach (var p in member.GetMethod.Parameters) { w.Write(head); WriteReferenceHtml(p.ParameterType, w, framework); w.Write(" <span class=\"c-ar\" title=\""); WriteEncoded(docs != null && docs.ParametersText.TryGetValue(p.Name, out var paramText) ? paramText : string.Empty, w); w.Write("\">"); WriteEncoded(p.Name, w); w.Write("</span>"); head = ", "; } w.Write("]"); } else { w.Write($" <a {href} id=\"{id}\" class=\"c-pd\">"); WriteEncoded(member.Name, w); w.Write("</a>"); } w.Write(" {"); if (member.GetMethod != null) { w.Write(" <span class=\"c-kw\">get</span>;"); } if (member.SetMethod != null) { if (member.SetMethod.IsPublic) { w.Write(" <span class=\"c-kw\">set</span>;"); } else if (member.SetMethod.IsFamily || member.SetMethod.IsFamilyOrAssembly) { w.Write(" <span class=\"c-kw\">protected set</span>;"); } } w.Write(" }"); }
private static void WriteGenericParameterListHtml(Collection <GenericParameter> genericParameters, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs) { w.Write("<"); var head = ""; foreach (var p in genericParameters) { w.Write(head); w.Write("<span class=\"c-tr\" title=\""); WriteEncoded(docs != null && docs.TypeParametersText.TryGetValue(p.Name, out var paramText) ? paramText : string.Empty, w); w.Write("\">"); WriteEncoded(p.Name, w); w.Write("</span>"); head = ", "; } w.Write(">"); }
public static void WritePrototypeHtml(this MethodDefinition member, TextWriter w, PackageTargetFramework framework, MemberXmlDocs docs, bool linkToCode, bool inExtensionClass) { if (!member.DeclaringType.IsInterface) { if (member.IsFamily || member.IsFamilyOrAssembly) { w.Write("<span class=\"c-kw\">protected</span> "); } else if (member.IsPublic) { w.Write("<span class=\"c-kw\">public</span> "); } if (member.IsStatic) { w.Write("<span class=\"c-kw\">static</span> "); } } var id = member.GetXmlName(); var href = GetHref(member, framework, linkToCode); if (member.IsConstructor) { w.Write($"<a {href} id=\"{id}\" class=\"c-cd\">"); var name = member.DeclaringType.Name; var ni = name.LastIndexOf('`'); if (ni > 0) { name = name.Substring(0, ni); } WriteEncoded(name, w); } else { if (!member.DeclaringType.IsInterface) { if (member.IsAbstract) { w.Write("<span class=\"c-kw\">abstract</span> "); } else if (member.IsVirtual) { if (member.IsReuseSlot) { w.Write("<span class=\"c-kw\">override</span> "); } else if (!member.IsFinal) { w.Write("<span class=\"c-kw\">virtual</span> "); } } } WriteReferenceHtml(member.ReturnType, w, framework); w.Write($" <a {href} id=\"{id}\" class=\"c-md\">"); WriteEncoded(member.Name, w); } w.Write("</a>"); var head = ""; if (member.HasGenericParameters) { WriteGenericParameterListHtml(member.GenericParameters, w, framework, docs); } w.Write("("); head = ""; bool isExtensionMethod = inExtensionClass && member.HasExtensionAttribute(); foreach (var p in member.Parameters) { w.Write(head); WriteReferenceHtml(p.ParameterType, w, framework, p.IsOut, isExtensionMethod); w.Write(" <span class=\"c-ar\" title=\""); WriteEncoded(docs != null && docs.ParametersText.TryGetValue(p.Name, out var paramText) ? paramText : string.Empty, w); w.Write("\">"); WriteEncoded(p.Name, w); w.Write("</span>"); if (p.HasConstant) { w.Write(" = "); var constant = p.Constant; if (constant == null && p.ParameterType.IsValueType) { w.Write("<span class=\"c-nl\">default</span>"); } else { TypeDocumentation.WritePrimitiveHtml(constant, w); } } head = ", "; isExtensionMethod = false; } w.Write(")"); if (member.HasGenericParameters) { WriteGenericConstraintsHtml(member.GenericParameters, w, framework); } }