예제 #1
0
 /// <summary>
 /// 添加标签属性时的触发函数.用于设置自身的某些属性值
 /// </summary>
 /// <param name="name"></param>
 /// <param name="item"></param>
 protected override void OnAddingAttribute(string name, Attribute item)
 {
     switch (name)
     {
     case "index":
         this.Index = ParserHelper.CreateVariableIdentity(this.OwnerTemplate, item.Text);
         break;
     }
 }
예제 #2
0
        /// <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);

            if (this.NextExpression != null)
            {
                exp.NextExpression = (VariableExpression)(this.NextExpression.Clone(ownerTemplate));
                exp.NextExpression.ParentExpression = exp;
            }
            return(exp);
        }
예제 #3
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);

            VariableTag tag = new VariableTag(ownerTemplate, varExp);

            //解析属性列表
            ParseElementAttributes(tag, match);
            container.AppendChild(tag);

            return(tag);
        }
예제 #4
0
        /// <summary>
        /// 构建变量的字段列表
        /// </summary>
        /// <param name="variableId"></param>
        /// <param name="match"></param>
        /// <returns></returns>
        internal static VariableExpression CreateVariableExpression(VariableIdentity variableId, Match match)
        {
            //解析变量字段列表
            VariableExpression field   = new VariableExpression(variableId);
            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);
        }
예제 #5
0
        /// <summary>
        /// 从变量表达式文本(如:name.age)中构建变量表达式
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <param name="expressionText"></param>
        /// <returns></returns>
        internal static VariableExpression CreateVariableExpression(Template ownerTemplate, string expressionText)
        {
            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));
            }
            else
            {
                //非变量表达式
                throw new ParserException(string.Format("变量表达式\"{0}\"的定义格式错误", expressionText));
            }
        }
예제 #6
0
 /// <summary>
 /// 变量表达式
 /// </summary>
 /// <param name="variableId"></param>
 /// <param name="fieldName"></param>
 /// <param name="isMethod"></param>
 internal VariableExpression(VariableIdentity variableId, string fieldName, bool isMethod)
 {
     this.VariableId = variableId;
     this.FieldName  = fieldName;
     this.IsMethod   = isMethod;
 }
예제 #7
0
 /// <summary>
 /// 变量表达式
 /// </summary>
 /// <param name="variableId"></param>
 internal VariableExpression(VariableIdentity variableId) : this(variableId, null, false)
 {
 }