Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
 /// <summary>
 /// Gets information for the specified event.
 /// </summary>
 /// <param name="eventSignature">XML comment signature.</param>
 /// <param name="evt">The event information.</param>
 /// <returns>Returns true if found. Otherwise, false.</returns>
 internal bool TryGetEventInfo(XmlCommentSignature eventSignature, out EventInfoWithComment evt)
 {
     return(m_EventComments.TryGetValue(eventSignature, out evt));
 }
Beispiel #3
0
 /// <summary>
 /// Gets information for the specified field.
 /// </summary>
 /// <param name="fieldSignature">XML comment signature.</param>
 /// <param name="field">The field information.</param>
 /// <returns>Returns true if found. Otherwise, false.</returns>
 internal bool TryGetFieldInfo(XmlCommentSignature fieldSignature, out FieldInfoWithComment field)
 {
     return(m_FieldComments.TryGetValue(fieldSignature, out field));
 }
Beispiel #4
0
 /// <summary>
 /// Gets information for the specified property.
 /// </summary>
 /// <param name="propertySignature">XML comment signature.</param>
 /// <param name="property">The property information.</param>
 /// <returns>Returns true if found. Otherwise, false.</returns>
 internal bool TryGetPropertyInfo(XmlCommentSignature propertySignature, out PropertyInfoWithComment property)
 {
     return(m_PropertyComments.TryGetValue(propertySignature, out property));
 }
Beispiel #5
0
 /// <summary>
 /// Gets information for the specified method.
 /// </summary>
 /// <param name="methodSignature">XML comment signature.</param>
 /// <param name="method">The method information.</param>
 /// <returns>Returns true if found. Otherwise, false.</returns>
 internal bool TryGetMethodInfo(XmlCommentSignature methodSignature, out MethodInfoWithComment method)
 {
     return(m_MethodComments.TryGetValue(methodSignature, out method));
 }
Beispiel #6
0
 /// <summary>
 /// Gets information for the specified type.
 /// </summary>
 /// <param name="typeSignature">XML comment signature.</param>
 /// <param name="type">The type information.</param>
 /// <returns>Returns true if found. Otherwise, false.</returns>
 internal bool TryGetTypeInfo(XmlCommentSignature typeSignature, out TypeWithComment type)
 {
     return(m_TypeComments.TryGetValue(typeSignature, out type));
 }
Beispiel #7
0
        /// <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);
            }
        }