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


C# Tokenizer.Read方法代码示例

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


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

示例1: CompileLayout

        internal static LayoutRenderer[] CompileLayout(ConfigurationItemFactory configurationItemFactory, Tokenizer sr, bool isNested, out string text)
        {
            var result = new List<LayoutRenderer>();
            var literalBuf = new StringBuilder();

            int ch;

            int p0 = sr.Position;

            while ((ch = sr.Peek()) != -1)
            {
                if (isNested && (ch == '}' || ch == ':'))
                {
                    break;
                }

                sr.Read();

                if (ch == '$' && sr.Peek() == '{')
                {
                    if (literalBuf.Length > 0)
                    {
                        result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                        literalBuf.Length = 0;
                    }

                    LayoutRenderer newLayoutRenderer = ParseLayoutRenderer(configurationItemFactory, sr);
                    if (CanBeConvertedToLiteral(newLayoutRenderer))
                    {
                        newLayoutRenderer = ConvertToLiteral(newLayoutRenderer);
                    }

                    // layout renderer
                    result.Add(newLayoutRenderer);
                }
                else
                {
                    literalBuf.Append((char)ch);
                }
            }

            if (literalBuf.Length > 0)
            {
                result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                literalBuf.Length = 0;
            }

            int p1 = sr.Position;

            MergeLiterals(result);
            text = sr.Substring(p0, p1);

            return result.ToArray();
        }
开发者ID:ChadBurggraf,项目名称:NLog,代码行数:54,代码来源:LayoutParser.cs

示例2: ParseParameterName

        private static string ParseParameterName(Tokenizer sr)
        {
            int ch;
            int nestLevel = 0;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if ((ch == '=' || ch == '}' || ch == ':') && nestLevel == 0)
                    break;
                if (ch == '$')
                {
                    sr.Read();
                    nameBuf.Append('$');
                    if (sr.Peek() == '{')
                    {
                        nameBuf.Append('{');
                        nestLevel++;
                        sr.Read();
                    }
                    continue;
                }
                if (ch == '}')
                {
                    nestLevel--;
                }
                if (ch == '\\')
                {
                    // skip the backslash
                    sr.Read();

                    // append next character
                    nameBuf.Append((char)sr.Read());
                    continue;
                }
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:41,代码来源:LayoutParser.cs

示例3: ParseLayoutRendererName

        private static string ParseLayoutRendererName(Tokenizer sr)
        {
            int ch;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if (ch == ':' || ch == '}')
                    break;
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:15,代码来源:LayoutParser.cs

示例4: CompileLayout

        internal static LayoutRenderer[] CompileLayout(Tokenizer sr, bool isNested, out string text)
        {
            List<LayoutRenderer> result = new List<LayoutRenderer>();
            StringBuilder literalBuf = new StringBuilder();

            int ch;

            int p0 = sr.Position;

            while ((ch = sr.Peek()) != -1)
            {
                if (isNested && (ch == '}' || ch == ':'))
                {
                    break;
                }
                sr.Read();

                if (ch == '$' && sr.Peek() == '{')
                {
                    if (literalBuf.Length > 0)
                    {
                        result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                        literalBuf.Length = 0;
                    }

                    LayoutRenderer newLayoutRenderer = ParseLayoutRenderer(sr);
                    if (newLayoutRenderer.IsAppDomainFixed())
                        newLayoutRenderer = ConvertToLiteral(newLayoutRenderer);
                    result.Add(newLayoutRenderer);
                    // layout renderer
                }
                else
                {
                    literalBuf.Append((char)ch);
                }
            }

            if (literalBuf.Length > 0)
            {
                result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                literalBuf.Length = 0;
            }
            int p1 = sr.Position;

            MergeLiterals(result);
            text = sr.Substring(p0, p1);

            return result.ToArray();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:49,代码来源:LayoutParser.cs

示例5: ParseLayoutRenderer

        private static LayoutRenderer ParseLayoutRenderer(Tokenizer sr)
        {
            int ch;

            ch = sr.Read();
            if (ch != '{')
                throw new NLogConfigurationException("'{' expected in layout specification");

            string name = ParseLayoutRendererName(sr);
            LayoutRenderer lr = LayoutRendererFactory.CreateLayoutRenderer(name, null);

            ch = sr.Read();
            while (ch != -1 && ch != '}')
            {
                string parameterName = ParseParameterName(sr).Trim();
                if (sr.Peek() == '=')
                {
                    sr.Read(); // skip the '='
                    PropertyInfo pi = PropertyHelper.GetPropertyInfo(lr, parameterName);
                    if (pi == null)
                    {
                        ParseParameterValue(sr);
                    }
                    else
                    {
                        if (typeof(Layout) == pi.PropertyType)
                        {
                            Layout nestedLayout = new Layout();
                            string txt;
                            LayoutRenderer[] renderers = CompileLayout(sr, true, out txt);

                            nestedLayout.SetRenderers(renderers, txt);
                            pi.SetValue(lr, nestedLayout, null);
                        }
                        else
                        {
                            string value = ParseParameterValue(sr);
                            PropertyHelper.SetPropertyFromString(lr, parameterName, value, null);
                        }
                    }
                }
                else
                {
                    // what we've just read is not a parameterName, but a value
                    // assign it to a default property (denoted by empty string)

                    PropertyInfo pi = PropertyHelper.GetPropertyInfo(lr, "");
                    if (pi != null)
                    {
                        if (typeof(Layout) == pi.PropertyType)
                        {
                            pi.SetValue(lr, new Layout(parameterName), null);
                        }
                        else
                        {
                            string value = parameterName;
                            PropertyHelper.SetPropertyFromString(lr, pi.Name, value, null);
                        }
                    }
                    else
                    {
                        InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
                    }
                }
                ch = sr.Read();
            }
            return lr;
        }
开发者ID:pallmall,项目名称:WCell,代码行数:68,代码来源:LayoutParser.cs

示例6: ParseParameterValue

        private static string ParseParameterValue(Tokenizer sr)
        {
            int ch;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if (ch == ':' || ch == '}')
                    break;
                if (ch == '\\')
                {
                    // skip the backslash
                    sr.Read();

                    // append next character
                    nameBuf.Append((char)sr.Read());
                    continue;
                }
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:24,代码来源:LayoutParser.cs

示例7: ParseLayoutRenderer

        private static LayoutRenderer ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, Tokenizer sr)
        {
            int ch = sr.Read();
            Debug.Assert(ch == '{', "'{' expected in layout specification");

            string name = ParseLayoutRendererName(sr);
            LayoutRenderer lr = configurationItemFactory.LayoutRenderers.CreateInstance(name);

            var wrappers = new Dictionary<Type, LayoutRenderer>();
            var orderedWrappers = new List<LayoutRenderer>();

            ch = sr.Read();
            while (ch != -1 && ch != '}')
            {
                string parameterName = ParseParameterName(sr).Trim();
                if (sr.Peek() == '=')
                {
                    sr.Read(); // skip the '='
                    PropertyInfo pi;
                    LayoutRenderer parameterTarget = lr;

                    if (!PropertyHelper.TryGetPropertyInfo(lr, parameterName, out pi))
                    {
                        Type wrapperType;

                        if (configurationItemFactory.AmbientProperties.TryGetDefinition(parameterName, out wrapperType))
                        {
                            LayoutRenderer wrapperRenderer;

                            if (!wrappers.TryGetValue(wrapperType, out wrapperRenderer))
                            {
                                wrapperRenderer = configurationItemFactory.AmbientProperties.CreateInstance(parameterName);
                                wrappers[wrapperType] = wrapperRenderer;
                                orderedWrappers.Add(wrapperRenderer);
                            }

                            if (!PropertyHelper.TryGetPropertyInfo(wrapperRenderer, parameterName, out pi))
                            {
                                pi = null;
                            }
                            else
                            {
                                parameterTarget = wrapperRenderer;
                            }
                        }
                    }

                    if (pi == null)
                    {
                        ParseParameterValue(sr);
                    }
                    else
                    {
                        if (typeof(Layout).IsAssignableFrom(pi.PropertyType))
                        {
                            var nestedLayout = new SimpleLayout();
                            string txt;
                            LayoutRenderer[] renderers = CompileLayout(configurationItemFactory, sr, true, out txt);

                            nestedLayout.SetRenderers(renderers, txt);
                            pi.SetValue(parameterTarget, nestedLayout, null);
                        }
                        else
                        {
                            string value = ParseParameterValue(sr);
                            PropertyHelper.SetPropertyFromString(parameterTarget, parameterName, value);
                        }
                    }
                }
                else
                {
                    // what we've just read is not a parameterName, but a value
                    // assign it to a default property (denoted by empty string)
                    PropertyInfo pi;

                    if (PropertyHelper.TryGetPropertyInfo(lr, string.Empty, out pi))
                    {
                        if (typeof(SimpleLayout) == pi.PropertyType)
                        {
                            pi.SetValue(lr, new SimpleLayout(parameterName), null);
                        }
                        else
                        {
                            string value = parameterName;
                            PropertyHelper.SetPropertyFromString(lr, pi.Name, value);
                        }
                    }
                    else
                    {
                        InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
                    }
                }

                ch = sr.Read();
            }

            lr = ApplyWrappers(configurationItemFactory, lr, orderedWrappers);

            return lr;
        }
开发者ID:ChadBurggraf,项目名称:NLog,代码行数:100,代码来源:LayoutParser.cs


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