Exemple #1
0
        /// <summary>
        /// Creates a <see cref="TagHelperDesignTimeDescriptor"/> from the given <paramref name="type"/>.
        /// </summary>
        /// <param name="type">
        /// The <see cref="Type"/> to create a <see cref="TagHelperDesignTimeDescriptor"/> from.
        /// </param>
        /// <returns>A <see cref="TagHelperDesignTimeDescriptor"/> that describes design time specific information
        /// for the given <paramref name="type"/>.</returns>
        public static TagHelperDesignTimeDescriptor CreateDescriptor(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var id = XmlDocumentationProvider.GetId(type);
            var documentationDescriptor = CreateDocumentationDescriptor(type.Assembly, id);

            // Purposefully not using the TypeInfo.GetCustomAttributes method here to make it easier to mock the Type.
            var outputElementHintAttribute = type
                                             .GetCustomAttributes(inherit: false)
                                             ?.OfType <OutputElementHintAttribute>()
                                             .FirstOrDefault();
            var outputElementHint = outputElementHintAttribute?.OutputElement;

            if (documentationDescriptor != null || outputElementHint != null)
            {
                return(new TagHelperDesignTimeDescriptor
                {
                    Summary = documentationDescriptor?.Summary,
                    Remarks = documentationDescriptor?.Remarks,
                    OutputElementHint = outputElementHint
                });
            }

            return(null);
        }
Exemple #2
0
        public void GetId_UnderstandsTypeInfo()
        {
            // Arrange
            var expectedId = "T:" + typeof(DocumentedTagHelper).FullName;

            // Act
            var id = XmlDocumentationProvider.GetId(DocumentedTagHelperTypeInfo);

            // Assert
            Assert.Equal(expectedId, id, StringComparer.Ordinal);
        }
Exemple #3
0
        public void GetId_UnderstandsPropertyInfo()
        {
            // Arrange
            var expectedId = string.Format(
                CultureInfo.InvariantCulture,
                "P:{0}.{1}",
                typeof(DocumentedTagHelper).FullName,
                nameof(DocumentedTagHelper.RemarksAndSummaryProperty));

            // Act
            var id = XmlDocumentationProvider.GetId(DocumentedTagHelperRemarksSummaryPropertyInfo);

            // Assert
            Assert.Equal(expectedId, id, StringComparer.Ordinal);
        }
        /// <summary>
        /// Creates a <see cref="TagHelperAttributeDesignTimeDescriptor"/> from the given
        /// <paramref name="propertyInfo"/>.
        /// </summary>
        /// <param name="propertyInfo">
        /// The <see cref="PropertyInfo"/> to create a <see cref="TagHelperAttributeDesignTimeDescriptor"/> from.
        /// </param>
        /// <returns>A <see cref="TagHelperAttributeDesignTimeDescriptor"/> that describes design time specific
        /// information for the given <paramref name="propertyInfo"/>.</returns>
        public static TagHelperAttributeDesignTimeDescriptor CreateAttributeDescriptor(
            [NotNull] PropertyInfo propertyInfo)
        {
            var id = XmlDocumentationProvider.GetId(propertyInfo);
            var declaringAssembly       = propertyInfo.DeclaringType.Assembly;
            var documentationDescriptor = CreateDocumentationDescriptor(declaringAssembly, id);

            if (documentationDescriptor != null)
            {
                return(new TagHelperAttributeDesignTimeDescriptor(
                           documentationDescriptor.Summary,
                           documentationDescriptor.Remarks));
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Creates a <see cref="TagHelperAttributeDesignTimeDescriptor"/> from the given
        /// <paramref name="propertyInfo"/>.
        /// </summary>
        /// <param name="propertyInfo">
        /// The <see cref="PropertyInfo"/> to create a <see cref="TagHelperAttributeDesignTimeDescriptor"/> from.
        /// </param>
        /// <returns>A <see cref="TagHelperAttributeDesignTimeDescriptor"/> that describes design time specific
        /// information for the given <paramref name="propertyInfo"/>.</returns>
        public static TagHelperAttributeDesignTimeDescriptor CreateAttributeDescriptor(
            PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            var id = XmlDocumentationProvider.GetId(propertyInfo);
            var declaringAssembly       = propertyInfo.DeclaringType.Assembly;
            var documentationDescriptor = CreateDocumentationDescriptor(declaringAssembly, id);

            if (documentationDescriptor != null)
            {
                return(new TagHelperAttributeDesignTimeDescriptor
                {
                    Summary = documentationDescriptor.Summary,
                    Remarks = documentationDescriptor.Remarks
                });
            }

            return(null);
        }