本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteComment方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteComment方法的具体用法?C# JsonWriter.WriteComment怎么用?C# JsonWriter.WriteComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteComment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
DateTime result = (DateTime)value;
TimeSpan delta = result.Subtract(mEpoch);
writer.WriteComment(delta.TotalSeconds.ToString());
}
示例2: Dump
// To aid debugging
public void Dump(JsonWriter j)
{
var n = l.First;
int i = 0;
j.WriteComment("VariableTracker ========");
if (n == null) {
return;
}
do {
j.WriteComment(string.Format(" {0}: {1} ", i, n.Value.DisplayName));
n = n.Next;
i++;
} while (n != null);
}
示例3: WriteJsonValue
private static void WriteJsonValue(JsonWriter writer, MemberInfo field, object value, Type type)
{
writer.WritePropertyName(field.Name);
if (type.IsEnum)
{
var e = Enum.GetName(type, value);
if (value is DateTime)
writer.WriteValue(e ?? ((DateTime)value).ToString("yyyy-MM-dd"));
else
writer.WriteValue(e ?? value.ToString());
writer.WriteRaw("\t");
writer.WriteComment(
string.Concat(type.GetCustomAttribute<FlagsAttribute>() != null ? "flags " : "enum ",
type.Name, " { ",
string.Join(", ", Enum.GetNames(type)), " }"));
}
else
{
if (type.IsPrimitive)
writer.WriteValue(value);
else
_serializer.Serialize(writer, value);
}
var info = field as PropertyInfo;
if (info != null && info.GetSetMethod() == null)
{
writer.WriteRaw("\t");
writer.WriteComment("readonly");
}
var ca = field.GetCustomAttribute<ConfigCommentAttribute>();
if (string.IsNullOrEmpty(ca?.Comment)) return;
writer.WriteRaw("\t");
writer.WriteComment(ca.Comment);
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteComment(value.ToString());
}
示例5: JsonReaderToJsonWriter
public void JsonReaderToJsonWriter(JsonReader reader, JsonWriter writer)
{
do
{
switch (reader.TokenType)
{
case JsonToken.None:
break;
case JsonToken.StartObject:
writer.WriteStartObject();
break;
case JsonToken.StartArray:
writer.WriteStartArray();
break;
case JsonToken.PropertyName:
string propertyName = reader.Value.ToString();
writer.WritePropertyName(ConvertPropertyName(propertyName));
break;
case JsonToken.Comment:
writer.WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Integer:
writer.WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Float:
object value = reader.Value;
if (value is decimal)
{
writer.WriteValue((decimal)value);
}
else if (value is double)
{
writer.WriteValue((double)value);
}
else if (value is float)
{
writer.WriteValue((float)value);
}
else
{
writer.WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
}
break;
case JsonToken.String:
writer.WriteValue(reader.Value.ToString());
break;
case JsonToken.Boolean:
writer.WriteValue(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));
break;
case JsonToken.Null:
if (this.PropertyNullValueReplaceValue != null)
{
writer.WriteValue(this.PropertyNullValueReplaceValue);
}
else
{
writer.WriteNull();
}
break;
case JsonToken.Undefined:
writer.WriteUndefined();
break;
case JsonToken.EndObject:
writer.WriteEndObject();
break;
case JsonToken.EndArray:
writer.WriteEndArray();
break;
case JsonToken.EndConstructor:
writer.WriteEndConstructor();
break;
case JsonToken.Date:
if (reader.Value is DateTimeOffset)
{
writer.WriteValue((DateTimeOffset)reader.Value);
}
else
{
writer.WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
}
break;
case JsonToken.Raw:
writer.WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
break;
case JsonToken.Bytes:
if (reader.Value is Guid)
{
writer.WriteValue((Guid)reader.Value);
}
else
{
writer.WriteValue((byte[])reader.Value);
}
break;
}
} while (reader.Read());
}
示例6: SerializeNode
private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
{
switch (node.NodeType)
{
case XmlNodeType.Element:
if (this.IsArray(node) && (Enumerable.All<IXmlNode>((IEnumerable<IXmlNode>) node.ChildNodes, (Func<IXmlNode, bool>) (n => n.LocalName == node.LocalName)) && node.ChildNodes.Count > 0))
{
this.SerializeGroupedNodes(writer, node, manager, false);
break;
}
else
{
foreach (IXmlNode xmlNode in (IEnumerable<IXmlNode>) node.Attributes)
{
if (xmlNode.NamespaceUri == "http://www.w3.org/2000/xmlns/")
{
string prefix = xmlNode.LocalName != "xmlns" ? xmlNode.LocalName : string.Empty;
manager.AddNamespace(prefix, xmlNode.Value);
}
}
if (writePropertyName)
writer.WritePropertyName(this.GetPropertyName(node, manager));
if (!Enumerable.Any<IXmlNode>(this.ValueAttributes((IEnumerable<IXmlNode>) node.Attributes)) && node.ChildNodes.Count == 1 && node.ChildNodes[0].NodeType == XmlNodeType.Text)
{
writer.WriteValue(node.ChildNodes[0].Value);
break;
}
else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty<IXmlNode>((ICollection<IXmlNode>) node.Attributes))
{
writer.WriteNull();
break;
}
else
{
writer.WriteStartObject();
for (int index = 0; index < node.Attributes.Count; ++index)
this.SerializeNode(writer, node.Attributes[index], manager, true);
this.SerializeGroupedNodes(writer, node, manager, true);
writer.WriteEndObject();
break;
}
}
case XmlNodeType.Attribute:
case XmlNodeType.Text:
case XmlNodeType.CDATA:
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
if (node.NamespaceUri == "http://www.w3.org/2000/xmlns/" && node.Value == "http://james.newtonking.com/projects/json" || node.NamespaceUri == "http://james.newtonking.com/projects/json" && node.LocalName == "Array")
break;
if (writePropertyName)
writer.WritePropertyName(this.GetPropertyName(node, manager));
writer.WriteValue(node.Value);
break;
case XmlNodeType.Comment:
if (!writePropertyName)
break;
writer.WriteComment(node.Value);
break;
case XmlNodeType.Document:
case XmlNodeType.DocumentFragment:
this.SerializeGroupedNodes(writer, node, manager, writePropertyName);
break;
case XmlNodeType.XmlDeclaration:
IXmlDeclaration xmlDeclaration = (IXmlDeclaration) node;
writer.WritePropertyName(this.GetPropertyName(node, manager));
writer.WriteStartObject();
if (!string.IsNullOrEmpty(xmlDeclaration.Version))
{
writer.WritePropertyName("@version");
writer.WriteValue(xmlDeclaration.Version);
}
if (!string.IsNullOrEmpty(xmlDeclaration.Encoding))
{
writer.WritePropertyName("@encoding");
writer.WriteValue(xmlDeclaration.Encoding);
}
if (!string.IsNullOrEmpty(xmlDeclaration.Standalone))
{
writer.WritePropertyName("@standalone");
writer.WriteValue(xmlDeclaration.Standalone);
}
writer.WriteEndObject();
break;
default:
throw new JsonSerializationException("Unexpected XmlNodeType when serializing nodes: " + (object) node.NodeType);
}
}
示例7: Indenting
public void Indenting()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonWriter(sw))
{
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("CPU");
jsonWriter.WriteValue("Intel");
jsonWriter.WritePropertyName("PSU");
jsonWriter.WriteValue("500W");
jsonWriter.WritePropertyName("Drives");
jsonWriter.WriteStartArray();
jsonWriter.WriteValue("DVD read/writer");
jsonWriter.WriteComment("(broken)");
jsonWriter.WriteValue("500 gigabyte hard drive");
jsonWriter.WriteValue("200 gigabype hard drive");
jsonWriter.WriteEnd();
jsonWriter.WriteEndObject();
}
string expected = @"{
""CPU"": ""Intel"",
""PSU"": ""500W"",
""Drives"": [
""DVD read/writer""
/*(broken)*/,
""500 gigabyte hard drive"",
""200 gigabype hard drive""
]
}";
string result = sb.ToString();
Console.WriteLine("Indenting");
Console.WriteLine(result);
Assert.AreEqual(expected, result);
}
示例8: WriteTo
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters) {
base.WriteTo(writer, converters);
if (this.WithComment) writer.WriteComment(Comment);
}
示例9: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteComment(ToString((RdioObjectType) value));
}