本文整理汇总了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;
}
}
示例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("}");
}
示例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");
}
}