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


C# StringTemplate.GetAttributeRenderer方法代码示例

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


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

示例2: Write

        /// <summary>
        /// Write o relative to self to out
        /// </summary>
        /// <remarks>
        /// John Snyders fixes here for formatString.  Basically, any time
        /// you are about to write a value, check formatting.
        /// </remarks>
        protected internal virtual int Write(StringTemplate self, object o, IStringTemplateWriter output)
        {
            if (o == null)
            {
                if (nullValue == null)
                {
                    return 0;
                }
                // continue with null option if specified
                o = nullValue;
            }
            int n = 0;
            try
            {
                if (o is StringTemplate)
                {
                    StringTemplate stToWrite = (StringTemplate) o;
                    // 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.IsInLintMode && StringTemplate.IsRecursiveEnclosingInstance(stToWrite))
                    {
                        // throw exception since sometimes eval keeps going
                        // even after I ignore this write of o.
                        throw new SystemException("infinite recursion to " + stToWrite.GetTemplateDeclaratorString() + " referenced in " + stToWrite.EnclosingInstance.GetTemplateDeclaratorString() + "; stack trace:\n" + stToWrite.GetEnclosingInstanceStackTrace());
                    }
                    else
                    {
                        // if we have a wrap string, then inform writer it
                        // might need to wrap
                        if (wrapString != null)
                        {
                            n = output.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.CreateInstanceOfTemplateWriter(buf);
                            stToWrite.Write(sw);
                            n = output.Write(renderer.ToString(buf.ToString(), formatString));
                            return n;
                        }
                    }
                        n = stToWrite.Write(output);
                    }
                    return n;
                }
                // normalize anything iteratable to iterator
                o = ConvertAnythingIteratableToIterator(o);
                if (o is IEnumerator)
                {
                    IEnumerator iter = (IEnumerator)o;
                    bool seenPrevValue = false;
                    while (iter.MoveNext())
                    {
                        object iterValue = iter.Current;
                        if (iterValue == null)
                        {
                            iterValue = nullValue;
                        }
                        if (iterValue != null)
                        {
                            if (seenPrevValue /*prevIterValue!=null*/ && (separatorString != null))
                            {
                                n += output.WriteSeparator(separatorString);
                            }
                            seenPrevValue = true;
                            int nw = Write(self, iterValue, output);
                            n += nw;
                        }
                    }
                }
                else
                {
                    IAttributeRenderer renderer = self.GetAttributeRenderer(o.GetType());
                    string v = null;
                    if (renderer != null)
                    {
                        if (formatString != null)
                        {
                            v = renderer.ToString(o, formatString);
//.........这里部分代码省略.........
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:101,代码来源:ASTExpr.cs

示例3: WriteObject

        protected virtual int WriteObject(StringTemplate self, object o, IStringTemplateWriter @out)
        {
            int n = 0;
            IAttributeRenderer renderer = self.GetAttributeRenderer(o.GetType());
            string v = null;
            if (renderer != null)
            {
                if (_formatString != null)
                    v = renderer.ToString(o, _formatString);
                else
                    v = renderer.ToString(o);
            }
            else
            {
                v = o.ToString();
            }

            if (_wrapString != null)
                n = @out.Write(v, _wrapString);
            else
                n = @out.Write(v);

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


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