/// <summary> /// Create a new instance. /// </summary> /// <param name="exceptionTypeSignature">The exception type signature.</param> /// <param name="descriptions">The descriptions.</param> /// <param name="context">The context that manages the state of the output process for class documents.</param> public ExceptionComment(string exceptionTypeSignature, string[] descriptions, ClassDocContext context) { Context = context; ExceptionTypeSignatureName = exceptionTypeSignature; Descriptions = descriptions; m_ExceptionType = null; if (XmlCommentSignature.TryParse(exceptionTypeSignature, out var signature)) { if (TypeLoader.TryGetType(signature.TypeName, out Type? type)) { m_ExceptionType = type; } } ExceptionTypeSignature = signature; }
/// <summary> /// Reads XML comments from the specified XML document. /// </summary> /// <param name="xDocument">The XML document.</param> /// <param name="context">The context that manages the state of the output process for class documents.</param> /// <param name="nameSpace">The namespace to read.</param> /// <returns>An Enumerator.</returns> internal static IEnumerable <XmlComment> ReadXmlComments(XDocument xDocument, ClassDocContext context, string?nameSpace = null) { string assemblyName = xDocument.Descendants("assembly").First().Elements("name").First().Value; IEnumerable <XmlComment?> documents = xDocument.Descendants("member") .Select(x => { // signature string signatureName = x.Attribute("name").Value; if (!XmlCommentSignature.TryParse(signatureName, out XmlCommentSignature signature)) { return(null); } string summary = FormatTextElement(x.Elements("summary")); string returns = FormatTextElement(x.Elements("returns")); string remarks = FormatTextElement(x.Elements("remarks")); // paeameter var parameters = x.Elements("param") .Select(element => (name: element.Attribute("name").Value, content: FormatTextElement(element))) .GroupBy(comment => comment.name) .ToDictionary(group => group.Key, g => new ParameterComment(g.Key, g.Select(v => v.content).ToArray(), context)) ; // type parameter var typeParameters = x.Elements("typeparam") .Select(element => (name: element.Attribute("name").Value, content: FormatTextElement(element))) .GroupBy(comment => comment.name) .ToDictionary(group => group.Key, g => new ParameterComment(g.Key, g.Select(v => v.content).ToArray(), context)) ; // exception var exceptions = x.Elements("exception") .Select(e => (name: e.Attribute("cref").Value, content: FormatTextElement(e))) .GroupBy(comment => comment.name) .ToDictionary(group => group.Key, g => new ExceptionComment(g.Key, g.Select(v => v.content).ToArray(), context)) .Values.ToArray(); // inheritdoc bool inheritdoc = x.Element("inheritdoc") != null; return(new XmlComment(context) { SignatureName = signatureName, IsInherit = inheritdoc, Signature = signature, Summary = summary.Trim(), Remarks = remarks.Trim(), ParametersInternal = parameters, TypeParametersInternal = typeParameters, Returns = returns.Trim(), ExceptionsInternal = exceptions, }); }); foreach (var doc in documents) { if (doc == null) { continue; } if (!string.IsNullOrWhiteSpace(nameSpace) && !doc.TypeName.StartsWith(nameSpace)) { continue; } // System.Diagnostics.Debug.WriteLine(doc.SignatureName); yield return(doc); } }