Пример #1
0
        /// <summary>Gets the description of the given member (based on the DescriptionAttribute, DisplayAttribute or XML Documentation).</summary>
        /// <param name="type">The member info</param>
        /// <param name="attributeType">The attribute type to check.</param>
        /// <returns>The description or null if no description is available.</returns>
        public static string GetDescription(this CachedType type, DescriptionAttributeType attributeType = DescriptionAttributeType.Context)
        {
            var attributes = type is ContextualType contextualType && attributeType == DescriptionAttributeType.Context ?
                             contextualType.ContextAttributes : type.TypeAttributes;

            dynamic descriptionAttribute = attributes.FirstAssignableToTypeNameOrDefault("System.ComponentModel.DescriptionAttribute");

            if (descriptionAttribute != null && !string.IsNullOrEmpty(descriptionAttribute.Description))
            {
                return(descriptionAttribute.Description);
            }
            else
            {
                dynamic displayAttribute = attributes.FirstAssignableToTypeNameOrDefault("System.ComponentModel.DataAnnotations.DisplayAttribute");
                if (displayAttribute != null)
                {
                    // GetDescription returns null if the Description property on the attribute is not specified.
                    var description = displayAttribute.GetDescription();
                    if (description != null)
                    {
                        return(description);
                    }
                }

                if (type is ContextualMemberInfo contextualMember)
                {
                    var summary = contextualMember.GetXmlDocsSummary();
                    if (summary != string.Empty)
                    {
                        return(summary);
                    }
                }
                else if (type != null)
                {
                    var summary = type.GetXmlDocsSummary();
                    if (summary != string.Empty)
                    {
                        return(summary);
                    }
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>Gets the description of the given member (based on the DescriptionAttribute, DisplayAttribute or XML Documentation).</summary>
        /// <param name="type">The member info</param>
        /// <returns>The description or null if no description is available.</returns>
        public static string GetDescription(this CachedType type)
        {
            var attributes = type is ContextualType contextualType ? contextualType.ContextAttributes : type.InheritedAttributes;

            var description = GetDescription(attributes);

            if (description != null)
            {
                return(description);
            }

            var summary = type.GetXmlDocsSummary();

            if (summary != string.Empty)
            {
                return(summary);
            }

            return(null);
        }
Пример #3
0
        /// <summary>Gets the description of the given member (based on the DescriptionAttribute, DisplayAttribute or XML Documentation).</summary>
        /// <param name="type">The member info</param>
        /// <param name="xmlDocsSettings">The XML Docs settings.</param>
        /// <returns>The description or null if no description is available.</returns>
        public static string GetDescription(this CachedType type, IXmlDocsSettings xmlDocsSettings)
        {
            var attributes = type is ContextualType contextualType ? contextualType.ContextAttributes : type.InheritedAttributes;

            var description = GetDescription(attributes);

            if (description != null)
            {
                return(description);
            }

            if (xmlDocsSettings.UseXmlDocumentation)
            {
                var summary = type.GetXmlDocsSummary(xmlDocsSettings.ResolveExternalXmlDocumentation);
                if (summary != string.Empty)
                {
                    return(summary);
                }
            }

            return(null);
        }