当前位置: 首页>>代码示例>>C#>>正文


C# StringTemplate.GetTemplateDeclaratorString方法代码示例

本文整理汇总了C#中StringTemplate.GetTemplateDeclaratorString方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate.GetTemplateDeclaratorString方法的具体用法?C# StringTemplate.GetTemplateDeclaratorString怎么用?C# StringTemplate.GetTemplateDeclaratorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringTemplate的用法示例。


在下文中一共展示了StringTemplate.GetTemplateDeclaratorString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteTemplate

        protected virtual int WriteTemplate(StringTemplate self, StringTemplate stToWrite, IStringTemplateWriter @out)
        {
            int n = 0;
            /* failsafe: perhaps enclosing instance not set
             * Or, it could be set to another context!  This occurs
             * when you store a template instance as an attribute of more
             * than one template (like both a header file and C file when
             * generating C code).  It must execute within the context of
             * the enclosing template.
             */
            stToWrite.EnclosingInstance = self;
            // if self is found up the enclosing instance chain, then infinite recursion
            if (StringTemplate.LintMode && StringTemplate.IsRecursiveEnclosingInstance(stToWrite))
            {
                // throw exception since sometimes eval keeps going even after I ignore this write of o.
                throw new InvalidOperationException("infinite recursion to " +
                        stToWrite.GetTemplateDeclaratorString() + " referenced in " +
                        stToWrite.EnclosingInstance.TemplateDeclaratorString +
                        "; stack trace:" + Environment.NewLine + stToWrite.GetEnclosingInstanceStackTrace());
            }
            else
            {
                // if we have a wrap string, then inform writer it might need to wrap
                if (_wrapString != null)
                {
                    n = @out.WriteWrapSeparator(_wrapString);
                }

                // check if formatting needs to be applied to the stToWrite
                if (_formatString != null)
                {
                    IAttributeRenderer renderer = self.GetAttributeRenderer(typeof(string));
                    if (renderer != null)
                    {
                        /* you pay a penalty for applying format option to a template
                         * because the template must be written to a temp StringWriter so it can
                         * be formatted before being written to the real output.
                         */
                        StringWriter buf = new StringWriter();
                        IStringTemplateWriter sw = self.Group.GetStringTemplateWriter(buf);
                        stToWrite.Write(sw);
                        n = @out.Write(renderer.ToString(buf.ToString(), _formatString));
                        return n;
                    }
                }

                n = stToWrite.Write(@out);
            }

            return n;
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:51,代码来源:ASTExpr.cs


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