Exemple #1
0
        private static void ValidateBinding(
            TagHelperBinding bindingResult,
            string tagName,
            Block tagBlock,
            ErrorSink errorSink)
        {
            // Ensure that all descriptors associated with this tag have appropriate TagStructures. Cannot have
            // multiple descriptors that expect different TagStructures (other than TagStructure.Unspecified).
            TagHelperDescriptor baseDescriptor = null;
            TagStructure?       baseStructure  = null;

            foreach (var descriptor in bindingResult.Descriptors)
            {
                var boundRules = bindingResult.GetBoundRules(descriptor);
                foreach (var rule in boundRules)
                {
                    if (rule.TagStructure != TagStructure.Unspecified)
                    {
                        // Can't have a set of TagHelpers that expect different structures.
                        if (baseStructure.HasValue && baseStructure != rule.TagStructure)
                        {
                            errorSink.OnError(
                                tagBlock.Start,
                                LegacyResources.FormatTagHelperParseTreeRewriter_InconsistentTagStructure(
                                    baseDescriptor.DisplayName,
                                    descriptor.DisplayName,
                                    tagName,
                                    nameof(TagMatchingRuleDescriptor.TagStructure)),
                                tagBlock.Length);
                        }

                        baseDescriptor = descriptor;
                        baseStructure  = rule.TagStructure;
                    }
                }
            }
        }