Example #1
0
 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate)
 {
     DMEWeb_ImportTag tag = new DMEWeb_ImportTag(ownerTemplate);
     this.CopyTo(tag);
     tag.Variable = this.Variable == null ? null : this.Variable.Clone(ownerTemplate);
     return tag;
 }
        /// <summary>
        /// 从表达式文本中构造表达式.如果表达式是以$字符开头.并且不是以$$字符开头.则认为是变量表达式.否则则认为是常量表达式
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <param name="expressionText"></param>
        /// <returns></returns>
        internal static DMEWeb_IExpression CreateExpression(DMEWeb_Template ownerTemplate, string expressionText)
        {
            if (string.IsNullOrEmpty(expressionText)) return new DMEWeb_ConstantExpression(expressionText);

            if (expressionText.StartsWith("$"))
            {
                expressionText = expressionText.Remove(0, 1);
                if (expressionText.StartsWith("$"))
                {
                    //$$字符开头.则认为是常量表达式
                    return new DMEWeb_ConstantExpression(expressionText);
                }
                else
                {
                    //变量表达式
                    return CreateVariableExpression(ownerTemplate, expressionText, false);
                }
            }
            else
            {
                //常量表达式
                return DMEWeb_Utility.IsInteger(expressionText) ?
                      new DMEWeb_ConstantExpression(DMEWeb_Utility.ConverToInt32(expressionText))
                    : new DMEWeb_ConstantExpression(expressionText);
            }
        }
Example #3
0
 /// <summary>
 /// 标签元素
 /// </summary>
 /// <param name="ownerTemplate">宿主模板</param>
 protected DMEWeb_Tag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.InnerElements = new DMEWeb_ElementCollection<DMEWeb_Element>();
     this.Attributes = new DMEWeb_AttributeCollection(this);
     //注册添加属性时触发事件.用于设置自身的某些属性值
     this.Attributes.Adding += OnAddingAttribute;
 }
Example #4
0
 /// <summary>
 /// 带变量字段的初始化
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="varExp"></param>
 internal DMEWeb_VariableTag(DMEWeb_Template ownerTemplate, DMEWeb_VariableExpression varExp)
     : base(ownerTemplate)
 {
     //注册添加属性时触发事件.用于设置自身的某些属性值
     this.Attributes = new DMEWeb_AttributeCollection(this);
     this.Attributes.Adding += OnAddingAttribute;
     this.VarExpression = varExp;
     this.CallFunctions = new List<DMEWeb_IExpression>();
 }
Example #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_Template(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.Visible = true;
     this.Charset = (ownerTemplate == null ? Encoding.Default : ownerTemplate.Charset);
     this.Variables = new VariableCollection();
     this.ChildTemplates = new DMEWeb_ElementCollection<DMEWeb_Template>();
     this.fileDependencies = new List<string>();
     this.UserDefinedFunctions = new DMEWeb_UserDefinedFunctionCollection();
     this.TagContainer = this;
 }
        /// <summary>
        /// 构建标签元素
        /// </summary>
        /// <param name="ownerTemplate">宿主模板</param>
        /// <param name="match"></param>
        /// <param name="isClosedTag">是否是自闭合标签</param>
        /// <returns></returns>
        internal static DMEWeb_Tag CreateTag(DMEWeb_Template ownerTemplate, Match match, out bool isClosedTag)
        {
            string tagName = match.Groups["tagname"].Value;
            isClosedTag = match.Groups["closed"].Success;

            DMEWeb_Tag tag = DMEWeb_TagFactory.FromTagName(ownerTemplate, tagName);
            if (tag == null) throw new DMEWeb_ParserException(string.Format("不能识别的元素标签\"{0}\"", tagName));

            ParseElementAttributes(tag, match);

            return tag;
        }
Example #7
0
 /// <summary>
 /// 根据标签名建立标签实例
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="tagName"></param>
 /// <returns></returns>
 internal static DMEWeb_Tag FromTagName(DMEWeb_Template ownerTemplate, string tagName)
 {
     if (!string.IsNullOrEmpty(tagName))
     {
         switch (tagName.ToLower())
         {
             case "for":
                 return new DMEWeb_ForTag(ownerTemplate);
             case "foreach":
                 return new DMEWeb_ForEachTag(ownerTemplate);
             case "foreachelse":
                 return new DMEWeb_ForEachElseTag(ownerTemplate);
             case "if":
                 return new DMEWeb_IfTag(ownerTemplate);
             case "elseif":
                 return new DMEWeb_IfConditionTag(ownerTemplate);
             case "else":
                 return new DMEWeb_ElseTag(ownerTemplate);
             case "template":
                 return new DMEWeb_Template(ownerTemplate);
             case "include":
                 return new DMEWeb_IncludeTag(ownerTemplate);
             case "expression":
                 return new DMEWeb_ExpressionTag(ownerTemplate);
             case "function":
                 return new FunctionTag(ownerTemplate);
             case "property":
                 return new DMEWeb_PropertyTag(ownerTemplate);
             case "serverdata":
                 return new DMEWeb_ServerDataTag(ownerTemplate);
             case "set":
                 return new DMEWeb_SetTag(ownerTemplate);
             case "import":
                 return new DMEWeb_ImportTag(ownerTemplate);
             case "output":
                 return new DMEWeb_OutputTag(ownerTemplate);
             case "datareader":
                 if (ownerTemplate.OwnerDocument.DocumentConfig != null
                     && ownerTemplate.OwnerDocument.DocumentConfig.TagOpenMode == DMEWeb_TagOpenMode.Full)
                 {
                     return new DMEWeb_DataReaderTag(ownerTemplate);
                 }
                 else
                 {
                     return null;
                 }
         }
     }
     return null;
 }
Example #8
0
        /// <summary>
        /// 根据前缀获取变量的模板所有者
        /// </summary>
        /// <param name="template"></param>
        /// <param name="prefix"></param>
        /// <returns>如果prefix值为null则返回template的根模板.如果为空值.则为template.如果为#则返回template的父模板.否则返回对应Id的模板</returns>
        internal static DMEWeb_Template GetOwnerTemplateByPrefix(DMEWeb_Template template, string prefix)
        {
            if (prefix == string.Empty) return template;               //前缀为空.则返回当前模板
            if (prefix == "#") return template.OwnerTemplate ?? template;   //前缀为#.则返回父模板(如果父模板不存在则返回当前模板)

            //取得根模板
            while (template.OwnerTemplate != null) template = template.OwnerTemplate;

            //如果没有前缀.则返回根模板.否则返回对应Id的模板
            return prefix == null ? template : template.GetChildTemplateById(prefix);
        }
Example #9
0
 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate)
 {
     DMEWeb_VariableTag tag = new DMEWeb_VariableTag(ownerTemplate, (DMEWeb_VariableExpression)this.VarExpression.Clone(ownerTemplate));
     foreach (var att in this.Attributes)
     {
         tag.Attributes.Add(att.Clone(ownerTemplate));
     }
     foreach (DMEWeb_IExpression exp in this.CallFunctions)
     {
         tag.CallFunctions.Add(exp.Clone(ownerTemplate));
     }
     return tag;
 }
 /// <summary>
 /// 克隆表达式
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 public DMEWeb_IExpression Clone(DMEWeb_Template ownerTemplate)
 {
     DMEWeb_VariableIdentity variableId = this.VariableId.Clone(ownerTemplate);
     DMEWeb_VariableExpression exp = new DMEWeb_VariableExpression(variableId, this.FieldName, this.IsMethod, this.NeedCacheData);
     if (this.NextExpression != null)
     {
         exp.NextExpression = (DMEWeb_VariableExpression)(this.NextExpression.Clone(ownerTemplate));
         exp.NextExpression.ParentExpression = exp;
     }
     return exp;
 }
Example #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_PropertyTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
 }
Example #12
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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.From == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少from属性", this.TagName));

            return base.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
        }
        /// <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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.Variable == null && !this.Output) throw new DMEWeb_ParserException(string.Format("{0}标签中如果未定义Output属性为true则必须定义var属性", this.TagName));
            if (this.Type == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少type属性或type属性值未知", this.TagName));
            //if (this.Type != ServerDataType.Random
            //    && this.Type != ServerDataType.Time
            //    && this.Type != ServerDataType.Request
            //    && this.Type != ServerDataType.Environment
            //    && this.Item == null) throw new ParserException(string.Format("当{0}标签type=\"{1}\"时必须设置item属性值", this.TagName, this.Type));

            return base.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
        }
Example #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_ImportTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
 }
Example #15
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 virtual bool ProcessBeginTag(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
 {
     container.AppendChild(this);
     return !isClosedTag;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_DataReaderTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.Parameters = new DMEWeb_ElementCollection<DMEWeb_IExpression>();
 }
        /// <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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.Variable == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少var属性", this.TagName));
            if (this.Connection == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少connection属性", this.TagName));
            if (this.CommandText == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少commandtext属性", this.TagName));

            return base.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
        }
 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate)
 {
     DMEWeb_DataReaderTag tag = new DMEWeb_DataReaderTag(ownerTemplate);
     this.CopyTo(tag);
     tag.Variable = this.Variable == null ? null : this.Variable.Clone(ownerTemplate);
     foreach (DMEWeb_IExpression exp in this.Parameters)
     {
         tag.Parameters.Add(exp.Clone(ownerTemplate));
     }
     return tag;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_IfConditionTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.Values = new DMEWeb_ElementCollection<DMEWeb_IExpression>();
 }
        /// <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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.Values.Count == 0) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少value属性", this.TagName));

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

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

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

            return true;
        }
Example #21
0
        /// <summary>
        /// 结束标签的解析
        /// </summary>
        /// <param name="ownerTemplate">模板宿主</param>
        /// <param name="container">元素容器</param>
        /// <param name="tagStack">标签堆栈</param>
        /// <param name="text"></param>
        /// <param name="match"></param>
        internal virtual void ProcessEndTag(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match)
        {
            int charOffset = 0, offset = 0;
            bool isClosedTag;

            charOffset = offset = match.Index + match.Length;
            match = null;
            while (offset < text.Length)
            {
                if (DMEWeb_ParserHelper.IsVariableTagStart(text, offset) && (match = DMEWeb_ParserRegex.VarTagRegex.Match(text, offset)).Success)                //匹配到模板变量
                {
                    //构建文本节点
                    DMEWeb_ParserHelper.CreateTextNode(ownerTemplate, container, text, charOffset, match.Index - charOffset);
                    //构建模板变量
                    DMEWeb_ParserHelper.CreateVariableTag(ownerTemplate, container, match);
                }
                else if (DMEWeb_ParserHelper.IsTagStart(text, offset) && (match = DMEWeb_ParserRegex.TagRegex.Match(text, offset)).Success)                     //匹配到某种类型的标签
                {
                    //构建文本节点
                    DMEWeb_ParserHelper.CreateTextNode(ownerTemplate, container, text, charOffset, match.Index - charOffset);
                    //构建标签
                    DMEWeb_Tag tag = DMEWeb_ParserHelper.CreateTag(ownerTemplate, match, out isClosedTag);

                    if (container.IsSingleTag && tag.IsSingleTag)
                    {
                        //如果前容器是单一标签并且当前标签也是单一标签.则回退到上一级非单元素标签
                        while (tagStack.Count > 0)
                        {
                            container = tagStack.Peek();
                            if (container.IsSingleTag)
                            {
                                tagStack.Pop();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    //将当前标签加入堆栈
                    tagStack.Push(tag);

                    //将解析权交给标签
                    bool flag = tag.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
                    //非已闭合标签或者是单标签则处理标签的结束标签
                    if (flag)
                    {
                        tag.ProcessEndTag(ownerTemplate, tag, tagStack, text, ref match);
                    }
                    if (tagStack.Count > 0 && tagStack.Peek() == tag && isClosedTag)
                    {
                        //闭合标签则回滚一级
                        tagStack.Pop();
                    }
                    if (tag.IsSingleTag)
                    {
                        //如果标签是单标签则退出寻找
                        break;
                    }
                    else
                    {
                        //取得容器
                        if (tagStack.Count > 0) container = tagStack.Peek();
                    }
                }
                else if (DMEWeb_ParserHelper.IsCloseTagStart(text, offset) && (match = DMEWeb_ParserRegex.EndTagRegex.Match(text, offset)).Success)            //匹配到某个结束标签
                {
                    //构建文本节点
                    DMEWeb_ParserHelper.CreateTextNode(ownerTemplate, container, text, charOffset, match.Index - charOffset);
                    //取得标签名称
                    string name = match.Groups["tagname"].Value;

                    //回滚标签堆栈.直到回滚到同名称元素的上级为此
                    while (tagStack.Count > 0)
                    {
                        DMEWeb_Tag popTag = tagStack.Pop();
                        if (name.Equals(popTag.TagName, StringComparison.InvariantCultureIgnoreCase)) break;
                        if (!name.Equals(popTag.EndTagName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            //非匹配的结束标签.则模板有错
                            throw new DMEWeb_ParserException(string.Format("无效的结束标签,原期望的是{0}结束标签", popTag.EndTagName));
                        }
                    }
                    break;
                }
                else if (DMEWeb_ParserHelper.IsVTExpressionStart(text, offset))
                {
                    char s = DMEWeb_ParserHelper.ReadChar(text, offset + DMEWeb_ParserHelper.VTExpressionHead.Length);
                    int startOffset = offset + DMEWeb_ParserHelper.VTExpressionHead.Length + 1;
                    int lastOffset = text.IndexOf(s, offset + DMEWeb_ParserHelper.VTExpressionHead.Length + 1);
                    if (lastOffset == -1) throw new DMEWeb_ParserException(string.Format("无法找到VT表达式[{0}{1}]的结束标记[{1}]", DMEWeb_ParserHelper.VTExpressionHead, s));
                    string code = text.Substring(startOffset, lastOffset - startOffset);
                    if (code.Length > 0)
                    {
                        //构建文本节点
                        DMEWeb_ParserHelper.CreateTextNode(ownerTemplate, container, text, charOffset, offset - charOffset);
                        //解析表达式里的代码
                        new DMEWeb_TemplateDocument(ownerTemplate, container, code, ownerTemplate.OwnerDocument.DocumentConfig);
                    }
                    offset = lastOffset + 1;
                    charOffset = offset;
                    continue;
                }
                else if (DMEWeb_ParserHelper.IsCommentTagStart(text, offset))
                {
                    //构建文本节点
                    DMEWeb_ParserHelper.CreateTextNode(ownerTemplate, container, text, charOffset, offset - charOffset);

                    //找到注释的起始标记"<!--vt[",则直接查找结束标记"]-->"
                    offset = text.IndexOf(DMEWeb_ParserHelper.CommentTagEnd, offset + DMEWeb_ParserHelper.CommentTagStart.Length);
                    if (offset == -1) throw new DMEWeb_ParserException("无法找到注释的结束标记");
                    offset += DMEWeb_ParserHelper.CommentTagEnd.Length;
                    charOffset = offset;
                    continue;
                }
                //处理偏移位置
                if (match != null && match.Success)
                {
                    charOffset = offset = match.Index + match.Length;
                    match = null;
                }
                else
                {
                    offset++;
                }
            }

            if (match == null) throw new DMEWeb_ParserException(string.Format("{0}标签未闭合", container.TagName));
        }
Example #22
0
 /// <summary>
 /// 预解析模板数据
 /// </summary>
 /// <param name="renderInstance">模板解析器实例的配置</param>
 /// <param name="template">要解析处理的模板</param>
 internal static void PreRenderTemplate(string renderInstance, DMEWeb_Template template)
 {
     DMEWeb_ITemplateRender render = GetRenderInstance(renderInstance) as DMEWeb_ITemplateRender;
     if (render != null) render.PreRender(template);
 }
Example #23
0
 /// <summary>
 /// 从模板中获取某个变量.如果不存在此变量则添加新的变量
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="varName"></param>
 /// <returns></returns>
 internal static DMEWeb_Variable GetVariableOrAddNew(DMEWeb_Template ownerTemplate, string varName)
 {
     DMEWeb_Variable var = ownerTemplate.Variables[varName];
     if (var == null)
     {
         var = new DMEWeb_Variable(ownerTemplate, varName);
         ownerTemplate.Variables.Add(var);
     }
     return var;
 }
Example #24
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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            //判断标签的容器是否为IfTag标签
            if (!(container is DMEWeb_IfTag)) throw new DMEWeb_ParserException(string.Format("未找到和{0}标签对应的{1}标签", this.TagName, this.EndTagName));

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

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

            return true;
        }
Example #25
0
        /// <summary>
        /// 使用特性方法预解析模板数据
        /// </summary>
        /// <param name="renderInstance"></param>
        /// <param name="renderMethod"></param>
        /// <param name="template"></param>
        internal static void PreRenderTemplateByAttributeMethod(string renderInstance, string renderMethod, DMEWeb_Template template)
        {
            object render = GetRenderInstance(renderInstance);
            if (render != null)
            {
                //取得特性方法
                MethodInfo method = null;

                MethodInfo[] methods = render.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                foreach (MethodInfo m in methods)
                {
                    DMEWeb_TemplateRenderMethodAttribute att = System.Attribute.GetCustomAttribute(m, typeof(DMEWeb_TemplateRenderMethodAttribute)) as DMEWeb_TemplateRenderMethodAttribute;
                    if (att != null)
                    {
                        if (renderMethod.Equals(m.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            method = m;
                            break;
                        }
                    }
                }

                if (method != null)
                {
                    ParameterInfo[] pars = method.GetParameters();
                    if (pars.Length == 1 && pars[0].ParameterType == typeof(DMEWeb_Template))
                    {
                        method.Invoke(method.IsStatic ? null : render, new object[] { template });
                    }
                }
            }
        }
Example #26
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_ElseTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
 }
Example #27
0
        /// <summary>
        /// 克隆当前元素到新的宿主模板
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <returns></returns>
        internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate)
        {
            DMEWeb_ForEachTag tag = new DMEWeb_ForEachTag(ownerTemplate);
            this.CopyTo(tag);
            tag.Else = this.Else == null ? null : (DMEWeb_ForEachElseTag)(this.Else.Clone(ownerTemplate));
            tag.From = this.From == null ? null : (DMEWeb_VariableExpression)this.From.Clone(ownerTemplate);
            tag.Index = this.Index == null ? null : this.Index.Clone(ownerTemplate);
            tag.Item = this.Item == null ? null : this.Item.Clone(ownerTemplate);

            return tag;
        }
Example #28
0
 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override DMEWeb_Element Clone(DMEWeb_Template ownerTemplate)
 {
     DMEWeb_ElseTag tag = new DMEWeb_ElseTag(ownerTemplate);
     this.CopyTo((DMEWeb_IfConditionTag)tag);
     return tag;
 }
Example #29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal DMEWeb_ForEachTag(DMEWeb_Template ownerTemplate)
     : base(ownerTemplate)
 {
 }
Example #30
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(DMEWeb_Template ownerTemplate, DMEWeb_Tag container, Stack<DMEWeb_Tag> tagStack, string text, ref Match match, bool isClosedTag)
        {
            if (this.Variable == null && !this.Output) throw new DMEWeb_ParserException(string.Format("{0}标签中如果未定义Output属性为true则必须定义var属性", this.TagName));
            if (this.Field == null || string.IsNullOrEmpty(this.Field.Text)) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少field属性", this.TagName));
            if (this.Type == null) throw new DMEWeb_ParserException(string.Format("{0}标签中缺少type属性", this.TagName));

            return base.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
        }