Ejemplo n.º 1
0
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, TagName);
            var endRepeater = TryGetRequiredTag(startElement, EndTagName);
            var itemsSource = startElement.GetExpression();

            if (string.IsNullOrEmpty(itemsSource))
            {
                throw new Exception(MessageStrings.ItemsAreEmpty);
            }

            IEnumerable <XElement> elementsBetween = TraverseUtils.ElementsBetween(startElement, endRepeater).ToList();
            var repeaterTag = new RepeaterTag
            {
                Source              = itemsSource,
                StartRepeater       = startElement,
                EndRepeater         = endRepeater,
                MakeElementCallback = MakeElementCallback
            };

            var repeaterProcessor = new RepeaterProcessor
            {
                RepeaterTag = repeaterTag,
            };

            if (elementsBetween.Any())
            {
                this.GoDeeper(repeaterProcessor, elementsBetween.First());
            }

            parentProcessor.AddProcessor(repeaterProcessor);

            return(endRepeater);
        }
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, TagName);
            var endRepeater = TryGetRequiredTag(startElement, EndTagName);
            var itemsSource = startElement.GetExpression(); 

            if (string.IsNullOrEmpty(itemsSource))
            {
                throw new Exception(MessageStrings.ItemsAreEmpty);
            }

            IEnumerable<XElement> elementsBetween = TraverseUtils.ElementsBetween(startElement, endRepeater).ToList();
            var repeaterTag = new RepeaterTag
                {
                    Source = itemsSource,
                    StartRepeater = startElement,
                    EndRepeater = endRepeater,
                    MakeElementCallback = MakeElementCallback
                };

            var repeaterProcessor = new RepeaterProcessor
                {
                    RepeaterTag = repeaterTag,
                };
            
            if (elementsBetween.Any())
            {
                this.GoDeeper(repeaterProcessor, elementsBetween.First());
            }

            parentProcessor.AddProcessor(repeaterProcessor);

            return endRepeater;
        }