private static IEnumerable <TagHelperDescriptor> BuildTagHelperDescriptors(
            ITypeInfo typeInfo,
            string assemblyName,
            IEnumerable <TagHelperAttributeDescriptor> attributeDescriptors,
            IEnumerable <HtmlTargetElementAttribute> targetElementAttributes,
            IEnumerable <string> allowedChildren,
            bool designTime)
        {
            TagHelperDesignTimeDescriptor typeDesignTimeDescriptor = null;

#if !DOTNET5_4
            if (designTime)
            {
                var runtimeTypeInfo = typeInfo as RuntimeTypeInfo;
                if (runtimeTypeInfo != null)
                {
                    typeDesignTimeDescriptor =
                        TagHelperDesignTimeDescriptorFactory.CreateDescriptor(runtimeTypeInfo.TypeInfo.AsType());
                }
            }
#endif

            var typeName = typeInfo.FullName;

            // If there isn't an attribute specifying the tag name derive it from the name
            if (!targetElementAttributes.Any())
            {
                var name = typeInfo.Name;

                if (name.EndsWith(TagHelperNameEnding, StringComparison.OrdinalIgnoreCase))
                {
                    name = name.Substring(0, name.Length - TagHelperNameEnding.Length);
                }

                return(new[]
                {
                    BuildTagHelperDescriptor(
                        ToHtmlCase(name),
                        typeName,
                        assemblyName,
                        attributeDescriptors,
                        requiredAttributes: Enumerable.Empty <string>(),
                        allowedChildren: allowedChildren,
                        tagStructure: default(TagStructure),
                        parentTag: null,
                        designTimeDescriptor: typeDesignTimeDescriptor)
                });
            }

            return(targetElementAttributes.Select(
                       attribute =>
                       BuildTagHelperDescriptor(
                           typeName,
                           assemblyName,
                           attributeDescriptors,
                           attribute,
                           allowedChildren,
                           typeDesignTimeDescriptor)));
        }
示例#2
0
        public void CreateDescriptor_WithType_ReturnsExpectedDescriptors(
            Type tagHelperType,
            TagHelperDesignTimeDescriptor expectedDesignTimeDescriptor)
        {
            // Act
            var designTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(tagHelperType);

            // Assert
            Assert.Equal(expectedDesignTimeDescriptor, designTimeDescriptor, TagHelperDesignTimeDescriptorComparer.Default);
        }
示例#3
0
        public void CreateDescriptor_CapturesOutputElementHint(
            Type tagHelperType,
            TagHelperDesignTimeDescriptor expectedDescriptor)
        {
            // Act
            var descriptors = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(tagHelperType);

            // Assert
            Assert.Equal(expectedDescriptor, descriptors, TagHelperDesignTimeDescriptorComparer.Default);
        }
        private IEnumerable<TagHelperDescriptor> BuildTagHelperDescriptors(
            Type type,
            string assemblyName,
            IEnumerable<TagHelperAttributeDescriptor> attributeDescriptors,
            IEnumerable<HtmlTargetElementAttribute> targetElementAttributes,
            IEnumerable<string> allowedChildren)
        {
            TagHelperDesignTimeDescriptor typeDesignTimeDescriptor = null;

            if (_designTime)
            {
                typeDesignTimeDescriptor = _designTimeDescriptorFactory.CreateDescriptor(type);
            }

            var typeName = type.FullName;

            // If there isn't an attribute specifying the tag name derive it from the name
            if (!targetElementAttributes.Any())
            {
                var name = type.Name;

                if (name.EndsWith(TagHelperNameEnding, StringComparison.OrdinalIgnoreCase))
                {
                    name = name.Substring(0, name.Length - TagHelperNameEnding.Length);
                }

                return new[]
                {
                    BuildTagHelperDescriptor(
                        ToHtmlCase(name),
                        typeName,
                        assemblyName,
                        attributeDescriptors,
                        requiredAttributeDescriptors: Enumerable.Empty<TagHelperRequiredAttributeDescriptor>(),
                        allowedChildren: allowedChildren,
                        tagStructure: default(TagStructure),
                        parentTag: null,
                        designTimeDescriptor: typeDesignTimeDescriptor)
                };
            }

            return targetElementAttributes.Select(
                attribute =>
                    BuildTagHelperDescriptor(
                        typeName,
                        assemblyName,
                        attributeDescriptors,
                        attribute,
                        allowedChildren,
                        typeDesignTimeDescriptor));
        }
        private static IEnumerable <TagHelperDescriptor> BuildTagHelperDescriptors(
            TypeInfo typeInfo,
            string assemblyName,
            IEnumerable <TagHelperAttributeDescriptor> attributeDescriptors,
            IEnumerable <TargetElementAttribute> targetElementAttributes,
            bool designTime)
        {
            TagHelperDesignTimeDescriptor typeDesignTimeDescriptor = null;

#if !DNXCORE50
            if (designTime)
            {
                typeDesignTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(typeInfo.GetType());
            }
#endif

            var typeName = typeInfo.FullName;

            // If there isn't an attribute specifying the tag name derive it from the name
            if (!targetElementAttributes.Any())
            {
                var name = typeInfo.Name;

                if (name.EndsWith(TagHelperNameEnding, StringComparison.OrdinalIgnoreCase))
                {
                    name = name.Substring(0, name.Length - TagHelperNameEnding.Length);
                }

                return(new[]
                {
                    BuildTagHelperDescriptor(
                        ToHtmlCase(name),
                        typeName,
                        assemblyName,
                        attributeDescriptors,
                        requiredAttributes: Enumerable.Empty <string>(),
                        designTimeDescriptor: typeDesignTimeDescriptor)
                });
            }

            return(targetElementAttributes.Select(
                       attribute =>
                       BuildTagHelperDescriptor(
                           typeName,
                           assemblyName,
                           attributeDescriptors,
                           attribute,
                           typeDesignTimeDescriptor)));
        }
示例#6
0
        public void CreateDescriptor_WithLocalizedType_ReturnsExpectedDescriptors(
            Type tagHelperType,
            TagHelperDesignTimeDescriptor expectedDesignTimeDescriptor,
            string culture)
        {
            // Arrange
            TagHelperDesignTimeDescriptor designTimeDescriptor;

            // Act
            using (new CultureReplacer(culture))
            {
                designTimeDescriptor = TagHelperDesignTimeDescriptorFactory.CreateDescriptor(tagHelperType);
            }

            // Assert
            Assert.Equal(expectedDesignTimeDescriptor, designTimeDescriptor, TagHelperDesignTimeDescriptorComparer.Default);
        }
 private static TagHelperDescriptor BuildTagHelperDescriptor(
     string tagName,
     string typeName,
     string assemblyName,
     IEnumerable <TagHelperAttributeDescriptor> attributeDescriptors,
     IEnumerable <string> requiredAttributes,
     TagHelperDesignTimeDescriptor designTimeDescriptor)
 {
     return(new TagHelperDescriptor(
                prefix: string.Empty,
                tagName: tagName,
                typeName: typeName,
                assemblyName: assemblyName,
                attributes: attributeDescriptors,
                requiredAttributes: requiredAttributes,
                designTimeDescriptor: designTimeDescriptor));
 }
        private static TagHelperDescriptor BuildTagHelperDescriptor(
            string typeName,
            string assemblyName,
            IEnumerable <TagHelperAttributeDescriptor> attributeDescriptors,
            TargetElementAttribute targetElementAttribute,
            TagHelperDesignTimeDescriptor designTimeDescriptor)
        {
            var requiredAttributes = GetCommaSeparatedValues(targetElementAttribute.Attributes);

            return(BuildTagHelperDescriptor(
                       targetElementAttribute.Tag,
                       typeName,
                       assemblyName,
                       attributeDescriptors,
                       requiredAttributes,
                       designTimeDescriptor));
        }
        private static TagHelperDescriptor BuildTagHelperDescriptor(
            string typeName,
            string assemblyName,
            IEnumerable<TagHelperAttributeDescriptor> attributeDescriptors,
            HtmlTargetElementAttribute targetElementAttribute,
            IEnumerable<string> allowedChildren,
            TagHelperDesignTimeDescriptor designTimeDescriptor)
        {
            IEnumerable<TagHelperRequiredAttributeDescriptor> requiredAttributeDescriptors;
            TryGetRequiredAttributeDescriptors(targetElementAttribute.Attributes, errorSink: null, descriptors: out requiredAttributeDescriptors);

            return BuildTagHelperDescriptor(
                targetElementAttribute.Tag,
                typeName,
                assemblyName,
                attributeDescriptors,
                requiredAttributeDescriptors,
                allowedChildren,
                targetElementAttribute.ParentTag,
                targetElementAttribute.TagStructure,
                designTimeDescriptor);
        }
 private static TagHelperDescriptor BuildTagHelperDescriptor(
     string tagName,
     string typeName,
     string assemblyName,
     IEnumerable <TagHelperAttributeDescriptor> attributeDescriptors,
     IEnumerable <string> requiredAttributes,
     IEnumerable <string> allowedChildren,
     TagStructure tagStructure,
     TagHelperDesignTimeDescriptor designTimeDescriptor)
 {
     return(new TagHelperDescriptor
     {
         TagName = tagName,
         TypeName = typeName,
         AssemblyName = assemblyName,
         Attributes = attributeDescriptors,
         RequiredAttributes = requiredAttributes,
         AllowedChildren = allowedChildren,
         TagStructure = tagStructure,
         DesignTimeDescriptor = designTimeDescriptor
     });
 }
 private static TagHelperDescriptor BuildTagHelperDescriptor(
     string tagName,
     string typeName,
     string assemblyName,
     IEnumerable<TagHelperAttributeDescriptor> attributeDescriptors,
     IEnumerable<string> requiredAttributes,
     IEnumerable<string> allowedChildren,
     string parentTag,
     TagStructure tagStructure,
     TagHelperDesignTimeDescriptor designTimeDescriptor)
 {
     return new TagHelperDescriptor
     {
         TagName = tagName,
         TypeName = typeName,
         AssemblyName = assemblyName,
         Attributes = attributeDescriptors,
         RequiredAttributes = requiredAttributes,
         AllowedChildren = allowedChildren,
         RequiredParent = parentTag,
         TagStructure = tagStructure,
         DesignTimeDescriptor = designTimeDescriptor
     };
 }
        private static TagHelperDescriptor BuildTagHelperDescriptor(
            string typeName,
            string assemblyName,
            IEnumerable<TagHelperAttributeDescriptor> attributeDescriptors,
            HtmlTargetElementAttribute targetElementAttribute,
            IEnumerable<string> allowedChildren,
            TagHelperDesignTimeDescriptor designTimeDescriptor)
        {
            var requiredAttributes = GetCommaSeparatedValues(targetElementAttribute.Attributes);

            return BuildTagHelperDescriptor(
                targetElementAttribute.Tag,
                typeName,
                assemblyName,
                attributeDescriptors,
                requiredAttributes,
                allowedChildren,
                targetElementAttribute.ParentTag,
                targetElementAttribute.TagStructure,
                designTimeDescriptor);
        }