/// <summary>
 /// 变量表达式
 /// </summary>
 /// <param name="parentExp"></param>
 /// <param name="fieldName"></param>
 /// <param name="isMethod"></param>
 internal VariableExpression(VariableExpression parentExp, string fieldName, bool isMethod)
 {
     parentExp.NextExpression = this;
     this.ParentExpression = parentExp;
     this.VariableId = parentExp.VariableId;
     this.FieldName = fieldName;
     this.IsMethod = isMethod;
     this.NeedCacheData = parentExp.NeedCacheData;
 }
示例#2
0
 /// <summary>
 /// 带变量字段的初始化
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="varExp"></param>
 internal VariableTag(Template ownerTemplate, VariableExpression varExp)
     : base(ownerTemplate)
 {
     //注册添加属性时触发事件.用于设置自身的某些属性值
     this.Attributes = new AttributeCollection(this);
     this.Attributes.Adding += OnAddingAttribute;
     this.VarExpression = varExp;
     this.CallFunctions = new List<IExpression>();
 }
示例#3
0
        /// <summary>
        /// 添加标签属性时的触发函数.用于设置自身的某些属性值
        /// </summary>
        /// <param name="name"></param>
        /// <param name="item"></param>
        public override void OnAddingAttribute(string name, Attribute item)
        {
            switch (name)
            {
            case "from":
                VariableExpression ve = item.Value as VariableExpression;
                if (ve == null && this.OwnerDocument.DocumentConfig.CompatibleMode)
                {
                    ve = ParserHelper.CreateVariableExpression(this.OwnerTemplate, item.Text, false);
                }
                this.From = ve;
                break;

            case "item":
                this.Item = ParserHelper.CreateVariableIdentity(this.OwnerTemplate, item.Text);
                break;

            case "index":
                this.Index = ParserHelper.CreateVariableIdentity(this.OwnerTemplate, item.Text);
                break;
            }
        }
示例#4
0
        /// <summary>
        /// 输出表达式的原字符串数据
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append(this.VariableId.ToString());

            VariableExpression exp = this;

            while (exp != null)
            {
                if (!string.IsNullOrEmpty(exp.FieldName))
                {
                    buffer.Append(".");
                    buffer.Append(exp.FieldName);
                    if (exp.IsMethod)
                    {
                        buffer.Append("()");
                    }
                }
                exp = exp.NextExpression;
            }
            return(buffer.ToString());
        }
 /// <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;
 }
示例#6
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;
        }