本文整理匯總了C#中Newtonsoft.Json.JsonWriter.WithWriter方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonWriter.WithWriter方法的具體用法?C# JsonWriter.WithWriter怎麽用?C# JsonWriter.WithWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WithWriter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Entity entity = value as Entity;
if (entity == null)
{
writer.WriteNull();
return;
}
writer.StartObject();
writer
// Write id
.WithWriter(w =>
{
if (string.IsNullOrWhiteSpace(entity.Id) == false)
w.WriteProperty("__id", entity.Id);
})
// Write created by
.WriteProperty("__createdby", entity.CreatedBy)
// Write properties
.WithWriter(w =>
{
foreach (var property in entity.Properties)
w.WriteProperty(property.Key, property.Value);
})
.WithWriter( w => WriteJson(entity, w, serializer) )
.WithWriter(w =>
{
var attr = entity.Attributes.ToArray();
if (attr.Length > 0)
{
w.WriteProperty("__attributes")
.StartObject();
// Write attributes
for (int i = 0; i < attr.Length; i++)
w.WriteProperty(attr[i].Key, attr[i].Value);
w.EndObject();
}
})
.WithWriter(w =>
{
if (entity.Tags.Count() > 0)
w.WriteArray("__tags", entity.Tags);
});
writer.EndObject();
}