Ejemplo n.º 1
0
        /// <summary>
        /// 开始解析标签数据
        /// </summary>
        /// <param name="ownerTemplate">宿主模板</param>
        /// <param name="container">标签的容器</param>
        /// <param name="tagStack">标签堆栈</param>
        /// <param name="text"></param>
        /// <param name="match"></param>
        /// <param name="isClosedTag">是否闭合标签</param>
        /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns>
        internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.Values.Count == 0)
            {
                throw new ParserException(string.Format("{0}标签中缺少value属性", this.TagName));
            }

            //判断标签的容器是否为IfTag标签
            if (!(container is IfTag))
            {
                throw new ParserException(string.Format("未找到和{0}标签对应的{1}标签", this.TagName, this.EndTagName));
            }

            IfTag ifTag = (IfTag)container;

            //判断此条件是否带var属性.如果不带则设置为if的条件
            if (this.VarExpression == null)
            {
                this.VarExpression = ifTag.VarExpression;
            }

            //加入到If标签的ElseIf队列
            ifTag.AddElseCondition(this);

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 克隆当前元素到新的宿主模板
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        internal override Element Clone(Template ownerTemplate)
        {
            IfTag tag = new IfTag(ownerTemplate);

            this.CopyTo((IfConditionTag)tag);
            tag.Else = this.Else == null ? null : (ElseTag)(this.Else.Clone(ownerTemplate));

            foreach (IfConditionTag elseTag in this.ElseIfs)
            {
                tag.AddElseCondition((IfConditionTag)elseTag.Clone(ownerTemplate));
            }
            return(tag);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 解析标签数据
        /// </summary>
        /// <param name="ownerTemplate">宿主模板</param>
        /// <param name="container">标签的容器</param>
        /// <param name="tagStack">标签堆栈</param>
        /// <param name="text"></param>
        /// <param name="match"></param>
        /// <param name="isClosedTag">是否闭合标签</param>
        /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns>
        internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            //判断标签的容器是否为IfTag标签
            if (!(container is IfTag))
            {
                throw new ParserException(string.Format("未找到和{0}标签对应的{1}标签", this.TagName, this.EndTagName));
            }

            IfTag ifTag = (IfTag)container;

            if (ifTag.Else != null)
            {
                throw new ParserException(string.Format("{0}标签不能定义多个{1}标签", this.EndTagName, this.TagName));
            }

            //加入到If标签的Else节点
            ifTag.Else = this;

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 克隆当前元素到新的宿主模板
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        internal override Element Clone(Template ownerTemplate)
        {
            IfTag tag = new IfTag(ownerTemplate);
            this.CopyTo((IfConditionTag)tag);
            tag.Else = this.Else == null ? null : (ElseTag)(this.Else.Clone(ownerTemplate));

            foreach (IfConditionTag elseTag in this.ElseIfs)
            {
                tag.AddElseCondition((IfConditionTag)elseTag.Clone(ownerTemplate));
            }
            return tag;
        }