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


C# IFormatter.WriteLiteral方法代码示例

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


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

示例1: WriteNumber

            private void WriteNumber(IConvertible value, IFormatter formatter)
            {
                IFormattable formattable = (IFormattable)value;

                switch (this.GetNumberFormat(value))
                {
                    case NumberFormat.Decimal:
                        formatter.WriteLiteral(formattable.ToString(null, CultureInfo.InvariantCulture));
                        break;

                    case NumberFormat.Hexadecimal:
                        formatter.WriteLiteral("0x" + formattable.ToString("x", CultureInfo.InvariantCulture));
                        break;
                }
            }
开发者ID:jorik041,项目名称:JavaScriptLanguage,代码行数:15,代码来源:JavaScriptLanguage.cs

示例2: WriteWhileStatement

            private void WriteWhileStatement(IWhileStatement statement, IFormatter formatter)
            {
                this.WriteStatementSeparator(formatter);
                formatter.WriteKeyword("while");
                formatter.Write(" ");
                formatter.Write("(");
                if (statement.Condition != null)
                {

                    this.WriteExpression(statement.Condition, formatter);

                }
                else
                    formatter.WriteLiteral("true");
                formatter.Write(")");

                formatter.Write(" {");
                formatter.WriteLine();
                formatter.WriteIndent();
                if (statement.Body != null)
                {
                    this.WriteStatement(statement.Body, formatter);
                }
                formatter.WriteLine();
                formatter.WriteOutdent();
                formatter.Write("}");
            }
开发者ID:jorik041,项目名称:JavaScriptLanguage,代码行数:27,代码来源:JavaScriptLanguage.cs

示例3: WriteLiteralExpression

            private void WriteLiteralExpression(ILiteralExpression value, IFormatter formatter)
            {
                if (value.Value == null)
                {
                    formatter.WriteLiteral("null");
                }
                else if (value.Value is char)
                {
                    string text = new string(new char[] { (char)value.Value });
                    text = this.QuoteLiteralExpression(text);
                    formatter.WriteLiteral("\"" + text + "\"");
                }
                else if (value.Value is string)
                {
                    string text = (string)value.Value;
                    text = this.QuoteLiteralExpression(text);
                    formatter.WriteLiteral("\"" + text + "\"");
                }
                else if (value.Value is byte)
                {
                    this.WriteNumber((byte)value.Value, formatter);
                }
                else if (value.Value is sbyte)
                {
                    this.WriteNumber((sbyte)value.Value, formatter);
                }
                else if (value.Value is short)
                {
                    this.WriteNumber((short)value.Value, formatter);
                }
                else if (value.Value is ushort)
                {
                    this.WriteNumber((ushort)value.Value, formatter);
                }
                else if (value.Value is int)
                {
                    this.WriteNumber((int)value.Value, formatter);
                }
                else if (value.Value is uint)
                {
                    this.WriteNumber((uint)value.Value, formatter);
                }
                else if (value.Value is long)
                {
                    this.WriteNumber((long)value.Value, formatter);
                }
                else if (value.Value is ulong)
                {
                    this.WriteNumber((ulong)value.Value, formatter);
                }
                else if (value.Value is float)
                {
                    // TODO
                    formatter.WriteLiteral(((float)value.Value).ToString(CultureInfo.InvariantCulture));
                }
                else if (value.Value is double)
                {
                    // TODO
                    formatter.WriteLiteral(((double)value.Value).ToString("R", CultureInfo.InvariantCulture));
                }
                else if (value.Value is decimal)
                {
                    formatter.WriteLiteral(((decimal)value.Value).ToString(CultureInfo.InvariantCulture));
                }
                else if (value.Value is bool)
                {
                    formatter.WriteLiteral(((bool)value.Value) ? "true" : "false");
                }
                /*
                else if (expression.Value is byte[])
                {
                    formatter.WriteComment("{ ");

                    byte[] bytes = (byte[])expression.Value;
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        if (i != 0)
                        {
                            formatter.Write(", ");
                        }

                        formatter.WriteComment("0x" + bytes[i].ToString("X2", CultureInfo.InvariantCulture));
                    }

                    formatter.WriteComment(" }");
                }
                */
                else
                {
                    throw new ArgumentException("expression");
                }
            }
开发者ID:jorik041,项目名称:JavaScriptLanguage,代码行数:92,代码来源:JavaScriptLanguage.cs


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