Exemplo n.º 1
0
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, StartTagName);
            var startTag = startElement;

            if (string.IsNullOrEmpty(startTag.Value))
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, "If"));
            }

            var endTag = this.FindEndTag(startTag);

            var content    = TraverseUtils.ElementsBetween(startTag, endTag).ToList();
            var expression = startTag.GetExpression();

            var ifTag = new IfTag
            {
                Conidition = expression,
                EndIf      = endTag,
                IfContent  = content,
                StartIf    = startTag,
            };

            var ifProcessor = new IfProcessor {
                Tag = ifTag
            };

            if (content.Any())
            {
                this.GoDeeper(ifProcessor, content.First(), endTag);
            }
            parentProcessor.AddProcessor(ifProcessor);

            return(endTag);
        }
        public override XElement Parse(ITagProcessor parentProcessor, XElement startElement)
        {
            this.ValidateStartTag(startElement, StartTagName);
            var startTag = startElement;

            if (string.IsNullOrEmpty(startTag.Value))
            {
                throw new Exception(string.Format(MessageStrings.TagNotFoundOrEmpty, "If"));
            }

            var endTag = this.FindEndTag(startTag);

            var content = TraverseUtils.ElementsBetween(startTag, endTag).ToList();
            var expression = startTag.GetExpression();

            var ifTag = new IfTag
                            {
                                Conidition = expression,
                                EndIf = endTag,
                                IfContent = content,
                                StartIf = startTag,
                            };

            var ifProcessor = new IfProcessor { Tag = ifTag };
            if (content.Any())
            {
                this.GoDeeper(ifProcessor, content.First(), endTag);
            }            
            parentProcessor.AddProcessor(ifProcessor);

            return endTag;
        }