/// <summary>
 /// 变量表达式
 /// </summary>
 /// <param name="variableId"></param>
 /// <param name="fieldName"></param>
 /// <param name="isMethod"></param>
 /// <param name="needCacheData"></param>
 internal VariableExpression(VariableIdentity variableId, string fieldName, bool isMethod, bool needCacheData)
 {
     this.VariableId    = variableId;
     this.FieldName     = fieldName;
     this.IsMethod      = isMethod;
     this.NeedCacheData = needCacheData;
 }
Beispiel #2
0
 /// <summary>
 /// 添加标签属性时的触发函数.用于设置自身的某些属性值
 /// </summary>
 /// <param name="name"></param>
 /// <param name="item"></param>
 public override void OnAddingAttribute(string name, Attribute item)
 {
     switch (name)
     {
     case "index":
         this.Index = ParserHelper.CreateVariableIdentity(this.OwnerTemplate, item.Text);
         break;
     }
 }
        /// <summary>
        /// 克隆表达式
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        public IExpression Clone(Template ownerTemplate)
        {
            VariableIdentity   variableId = this.VariableId.Clone(ownerTemplate);
            VariableExpression exp        = new VariableExpression(variableId, this.FieldName, this.IsMethod, this.NeedCacheData);

            if (this.NextExpression != null)
            {
                exp.NextExpression = (VariableExpression)(this.NextExpression.Clone(ownerTemplate));
                exp.NextExpression.ParentExpression = exp;
            }
            return(exp);
        }
Beispiel #4
0
        /// <summary>
        /// 构建变量标签元素
        /// </summary>
        /// <param name="ownerTemplate">宿主模板</param>
        /// <param name="container">标签的容器</param>
        /// <param name="match"></param>
        internal static VariableTag CreateVariableTag(Template ownerTemplate, Tag container, Match match)
        {
            string prefix;
            Variable variable = CreateVariable(ownerTemplate, match, out prefix);
            VariableIdentity variableId = new VariableIdentity(ownerTemplate, variable, prefix);

            //变量标签元素则需要缓存表达式的值
            VariableExpression varExp = CreateVariableExpression(variableId, match, true);

            VariableTag tag = new VariableTag(ownerTemplate, varExp);
            //解析属性列表
            ParseElementAttributes(tag, match);
            container.AppendChild(tag);

            return tag;
        }
Beispiel #5
0
        /// <summary>
        /// 构建变量的字段列表
        /// </summary>
        /// <param name="variableId"></param>
        /// <param name="match"></param>
        /// <param name="needCacheData"></param>
        /// <returns></returns>
        internal static VariableExpression CreateVariableExpression(VariableIdentity variableId, Match match, bool needCacheData)
        {
            //解析变量字段列表
            VariableExpression field = new VariableExpression(variableId, needCacheData);
            CaptureCollection fields = match.Groups["field"].Captures;
            CaptureCollection methods = match.Groups["method"].Captures;
            VariableExpression item = field;
            for (var i = 0; i < fields.Count; i++)
            {
                string fieldName = fields[i].Value;
                VariableExpression exp = new VariableExpression(item, fieldName, !string.IsNullOrEmpty(methods[i].Value));
                item = exp;
            }

            return field;
        }
Beispiel #6
0
        /// <summary>
        /// 呈现本元素的数据
        /// </summary>
        /// <param name="writer"></param>
        protected override void RenderTagData(System.IO.TextWriter writer)
        {
            decimal from  = Utility.ConverToDecimal(this.From.Value.GetValue());
            decimal step  = this.Step == null ? 1 : Utility.ConverToDecimal(this.Step.Value.GetValue());
            decimal to    = Utility.ConverToDecimal(this.To.Value.GetValue());
            decimal index = from;

            LoopIndex li = new LoopIndex(index);

            if (this.Index != null)
            {
                this.Index.Value = li;
            }
            if (step >= 0)
            {
                while (index <= to)
                {
                    li.Value   = index;
                    li.IsFirst = (index == from);
                    li.IsLast  = (index == to);
                    if (this.Index != null)
                    {
                        this.Index.Variable.Reset();
                    }
                    base.RenderTagData(writer);
                    index += step;
                }
            }
            else
            {
                while (index >= to)
                {
                    li.Value   = index;
                    li.IsFirst = (index == from);
                    li.IsLast  = (index == to);
                    if (this.Index != null)
                    {
                        this.Index.Variable.Reset();
                    }
                    base.RenderTagData(writer);
                    index += step;
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 从变量表达式文本(如:name.age)中构建变量表达式
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <param name="expressionText"></param>
        /// <param name="needCacheData"></param>
        /// <returns></returns>
        internal static VariableExpression CreateVariableExpression(Template ownerTemplate, string expressionText, bool needCacheData)
        {
            if (string.IsNullOrEmpty(expressionText)) return null;

            Match match = ParserRegex.VarExpRegex.Match(expressionText);
            if (match.Success)
            {
                string prefix;
                Variable variable = CreateVariable(ownerTemplate, match, out prefix);
                VariableIdentity variableId = new VariableIdentity(ownerTemplate, variable, prefix);

                return CreateVariableExpression(variableId, match, needCacheData);
            }
            else
            {
                //非变量表达式
                throw new ParserException(string.Format("变量表达式\"{0}\"的定义格式错误", expressionText));
            }
        }
 /// <summary>
 /// 变量表达式
 /// </summary>
 /// <param name="variableId"></param>
 /// <param name="needCacheData"></param>
 public VariableExpression(VariableIdentity variableId, bool needCacheData)
     : this(variableId, null, false, needCacheData)
 {
 }