• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Engine.Template类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中VTemplate.Engine.Template的典型用法代码示例。如果您正苦于以下问题:C# Template类的具体用法?C# Template怎么用?C# Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Template类属于VTemplate.Engine命名空间,在下文中一共展示了Template类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateExpression

        /// <summary>
        /// 从表达式文本中构造表达式.如果表达式是以$字符开头.并且不是以$$字符开头.则认为是变量表达式.否则则认为是常量表达式
        /// </summary>
        /// <param name="ownerTemplate"></param>
        /// <param name="expressionText"></param>
        /// <returns></returns>
        internal static IExpression CreateExpression(Template ownerTemplate, string expressionText)
        {
            if (string.IsNullOrEmpty(expressionText)) return new ConstantExpression(expressionText);

            if (expressionText.StartsWith("$") && !"$=".Equals(expressionText)) //"$="认为是字符串常量
            {
                expressionText = expressionText.Remove(0, 1);
                if (expressionText.StartsWith("$"))
                {
                    //$$字符开头.则认为是常量表达式
                    return new ConstantExpression(expressionText);
                }
                else
                {
                    //变量表达式
                    return CreateVariableExpression(ownerTemplate, expressionText, false);
                }
            }
            else
            {
                //常量表达式
                return Utility.IsInteger(expressionText) ?
                      new ConstantExpression(Utility.ConverToInt32(expressionText))
                    : new ConstantExpression(expressionText);
            }
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:32,代码来源:ParserHelper.cs


示例2: Tag

 /// <summary>
 /// 标签元素
 /// </summary>
 /// <param name="ownerTemplate">宿主模板</param>
 protected Tag(Template ownerTemplate) : base(ownerTemplate)
 {            
     this.InnerElements = new ElementCollection<Element>();
     this.Attributes = new AttributeCollection(this);
     //注册添加属性时触发事件.用于设置自身的某些属性值
     this.Attributes.Adding += OnAddingAttribute;
 }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:11,代码来源:Tag.cs


示例3: PreRender

        /// <summary>
        /// 解析某个模板块的数据
        /// </summary>
        /// <param name="template"></param>
        public void PreRender(Template template)
        {
            //根据模板块里定义的type属性条件取得新闻数据
            List<News> newsData = NewsDbProvider.GetNewsData(template.Attributes.GetValue("type"));
            //设置变量newsdata的值
            template.Variables.SetValue("newsdata", newsData);

            //取得模板块下Id为newslist的标签(也即是在cnblogs_newsdata.html文件中定义的foreach标签)
            Tag tag = template.GetChildTagById("newslist");
            if (tag is ForEachTag)
            {
                //如果标签为foreach标签则设置其BeforeRender事件用于设置变量表达式{$:#.news.url}的值
                tag.BeforeRender += (sender, e) =>
                {
                    ForEachTag t = (ForEachTag)sender;

                    //取得当前项的值(因为foreach标签的数据源是List<News>集合,所以当前项的值类型为News实体)
                    News news = (News)t.Item.Value;
                    //设置当前项的变量表达式的值.也即是"{$:#.news.url}"变量表达式
                    t.Item.SetExpValue("url", NewsDbProvider.GetNewsUrl(news));

                    //当新闻不可见时.你可以取消本次输出
                    if (!news.Visible) e.Cancel = true;
                };
            }
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:30,代码来源:CnblogsNewsRender.cs


示例4: Clone

 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override Element Clone(Template ownerTemplate)
 {
     IncludeTag tag = new IncludeTag(ownerTemplate);
     this.CopyTo(tag);
     tag.File = this.File;
     tag.Charset = this.Charset;
     return tag;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:13,代码来源:IncludeTag.cs


示例5: VariableTag

 /// <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>();
 }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:14,代码来源:VariableTag.cs


示例6: Template

 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal Template(Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.Visible = true;
     this.Charset = (ownerTemplate == null ? Encoding.Default : ownerTemplate.Charset);
     this.Variables = new VariableCollection();
     this.ChildTemplates = new ElementCollection<Template>();
     this.fileDependencies = new List<string>();
     this.UserDefinedFunctions = new UserDefinedFunctionCollection();
     this.TagContainer = this;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:15,代码来源:Template.cs


示例7: ProcessBeginTag

        /// <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)
        {
            //判断标签的容器是否为ForEach标签
            if (!(container is ForEachTag)) throw new ParserException(string.Format("未找到和{0}标签对应的{1}标签", this.TagName, this.EndTagName));

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

            foreachTag.Else = this;

            return true;
        }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:22,代码来源:ForEachElseTag.cs


示例8: CreateTag

        /// <summary>
        /// 构建标签元素
        /// </summary>
        /// <param name="ownerTemplate">宿主模板</param>
        /// <param name="match"></param>
        /// <param name="isClosedTag">是否是自闭合标签</param>
        /// <returns></returns>
        internal static Tag CreateTag(Template ownerTemplate, Match match,out bool isClosedTag)
        {
            string tagName = match.Groups["tagname"].Value;
            isClosedTag = match.Groups["closed"].Success;

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

            ParseElementAttributes(tag, match);

            return tag;
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:19,代码来源:ParserHelper.cs


示例9: FromTagName

 /// <summary>
 /// 根据标签名建立标签实例
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="tagName"></param>
 /// <returns></returns>
 internal static Tag FromTagName(Template ownerTemplate, string tagName)
 {
     if (!string.IsNullOrEmpty(tagName))
     {
         switch (tagName.ToLower())
         {
             case "for":
                 return new ForTag(ownerTemplate);
             case "foreach":
                 return new ForEachTag(ownerTemplate);
             case "foreachelse":
                 return new ForEachElseTag(ownerTemplate);
             case "if":
                 return new IfTag(ownerTemplate);
             case "elseif":
                 return new IfConditionTag(ownerTemplate);
             case "else":
                 return new ElseTag(ownerTemplate);
             case "template":
                 return new Template(ownerTemplate);
             case "include":
                 return new IncludeTag(ownerTemplate);
             case "expression":
                 return new ExpressionTag(ownerTemplate);
             case "function":
                 return new FunctionTag(ownerTemplate);
             case "property":
                 return new PropertyTag(ownerTemplate);
             case "serverdata":
                 return new ServerDataTag(ownerTemplate);
             case "set":
                 return new SetTag(ownerTemplate);
             case "import":
                 return new ImportTag(ownerTemplate);
             case "output":
                 return new OutputTag(ownerTemplate);
             case "panel":
                 return new PanelTag(ownerTemplate);
             case "datareader":
                 if (ownerTemplate.OwnerDocument.DocumentConfig != null
                     && ownerTemplate.OwnerDocument.DocumentConfig.TagOpenMode == TagOpenMode.Full)
                 {
                     return new DataReaderTag(ownerTemplate);
                 }
                 else
                 {
                     return null;
                 }
         }
     }
     return null;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:58,代码来源:TagFactory.cs


示例10: ProcessBeginTag

        /// <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)
        {
            container.AppendChild(this);

            if (!string.IsNullOrEmpty(this.File))
            {
                //修正文件地址
                this.File = Utility.ResolveFilePath(this.Parent, this.File);

                if (System.IO.File.Exists(this.File))
                {
                    //增加到依赖文件列表
                    this.OwnerTemplate.AddFileDependency(this.File);

                    //解析数据
                    new TemplateDocument(ownerTemplate, this, System.IO.File.ReadAllText(this.File, this.Charset), ownerTemplate.OwnerDocument.DocumentConfig);
                }
            }
            return !isClosedTag;
        }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:30,代码来源:IncludeTag.cs


示例11: Clone

 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override Element Clone(Template ownerTemplate)
 {
     ForTag tag = new ForTag(ownerTemplate);
     base.CopyTo(tag);
     tag.Index = this.Index == null ? null : this.Index.Clone(ownerTemplate);
     return tag;
 }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:12,代码来源:ForTag.cs


示例12: Clone

 /// <summary>
 /// 克隆当前元素到新的宿主模板
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <returns></returns>
 internal override Element Clone(Template ownerTemplate)
 {
     SetTag tag = new SetTag(ownerTemplate);
     this.CopyTo(tag);
     tag.Variable = this.Variable == null ? null : this.Variable.Clone(ownerTemplate);
     tag.Output = this.Output;
     foreach (IExpression exp in this.Values)
     {
         tag.Values.Add((IExpression)(exp.Clone(ownerTemplate)));
     }
     return tag;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:17,代码来源:SetTag.cs


示例13: ProcessBeginTag

        /// <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.Variable == null && !this.Output) throw new ParserException(string.Format("{0}标签中如果未定义Output属性为true则必须定义var属性", this.TagName));
            if (this.Values.Count < 1) throw new ParserException(string.Format("{0}标签中缺少value属性", this.TagName));
            if (this.Values.Count > 1 && this.Format == null) throw new ParserException(string.Format("{0}标签如果已定义多个value属性,则也必须定义format属性", this.TagName));

            return base.ProcessBeginTag(ownerTemplate, container, tagStack, text, ref match, isClosedTag);
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:18,代码来源:SetTag.cs


示例14: PreRenderTemplateByAttributeMethod

        /// <summary>
        /// 使用特性方法预解析模板数据
        /// </summary>
        /// <param name="renderInstance"></param>
        /// <param name="renderMethod"></param>
        /// <param name="template"></param>
        internal static void PreRenderTemplateByAttributeMethod(string renderInstance, string renderMethod, 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)
                {
                    TemplateRenderMethodAttribute att = System.Attribute.GetCustomAttribute(m, typeof(TemplateRenderMethodAttribute)) as 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(Template))
                    {
                        method.Invoke(method.IsStatic ? null : render, new object[] { template });
                    }
                }
            }
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:38,代码来源:Utility.cs


示例15: GetVariableOrAddNew

 /// <summary>
 /// 从模板中获取某个变量.如果不存在此变量则添加新的变量
 /// </summary>
 /// <param name="ownerTemplate"></param>
 /// <param name="varName"></param>
 /// <returns></returns>
 internal static Variable GetVariableOrAddNew(Template ownerTemplate, string varName)
 {
     Variable var = ownerTemplate.Variables[varName];
     if (var == null)
     {
         var = new Variable(ownerTemplate, varName);
         ownerTemplate.Variables.Add(var);
     }
     return var;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:16,代码来源:Utility.cs


示例16: TemplateDocument

 /// <summary>
 /// 
 /// </summary>
 /// <param name="documentElement"></param>
 /// <param name="container"></param>
 /// <param name="text"></param>
 /// <param name="documentConfig"></param>
 internal TemplateDocument(Template documentElement, Tag container, string text, TemplateDocumentConfig documentConfig)
 {
     this.DocumentConfig = documentConfig;
     this.AppendChild(documentElement);
     this.ChildTemplates.Add(documentElement);
     this.ParseString(documentElement, container, text);
 }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:14,代码来源:TemplateDocument.cs


示例17: IncludeTag

 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal IncludeTag(Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.Charset = ownerTemplate.Charset;
 }
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:9,代码来源:IncludeTag.cs


示例18: IfTag

 /// <summary>
 /// 
 /// </summary>
 /// <param name="ownerTemplate"></param>
 internal IfTag(Template ownerTemplate)
     : base(ownerTemplate)
 {
     this.ElseIfs = new ElementCollection<IfConditionTag>();
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:9,代码来源:IfTag.cs


示例19: GetOwnerTemplateByPrefix

        /// <summary>
        /// 根据前缀获取变量的模板所有者
        /// </summary>
        /// <param name="template"></param>
        /// <param name="prefix"></param>
        /// <returns>如果prefix值为null则返回template的根模板.如果为空值.则为template.如果为#则返回template的父模板.否则返回对应Id的模板</returns>
        internal static Template GetOwnerTemplateByPrefix(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);
        }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:17,代码来源:Utility.cs


示例20: ProcessBeginTag

 /// <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(Template ownerTemplate, Tag container, Stack<Tag> tagStack, string text, ref Match match, bool isClosedTag)
 {
     container.AppendChild(this);
     return !isClosedTag;
 }
开发者ID:ysking,项目名称:net-vtemplate,代码行数:15,代码来源:Tag.cs



注:本文中的VTemplate.Engine.Template类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Common.ClientSecrets类代码示例发布时间:2022-05-26
下一篇:
C# VRageRender.PixelShaderId类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap