本文整理匯總了C#中Newtonsoft.Json.JsonSerializer.?.GetConnectionSettings方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonSerializer.?.GetConnectionSettings方法的具體用法?C# JsonSerializer.?.GetConnectionSettings怎麽用?C# JsonSerializer.?.GetConnectionSettings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.?.GetConnectionSettings方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var bulk = value as IBulkRequest;
var settings = serializer?.GetConnectionSettings();
var elasticsearchSerializer = settings?.Serializer;
if (elasticsearchSerializer == null|| bulk?.Operations == null) return ;
foreach(var op in bulk.Operations)
{
op.Index = op.Index ?? bulk.Index ?? op.ClrType;
if (op.Index.EqualsMarker(bulk.Index)) op.Index = null;
op.Type = op.Type ?? bulk.Type ?? op.ClrType;
if (op.Type.EqualsMarker(bulk.Type)) op.Type = null;
op.Id = op.GetIdForOperation(settings.Inferrer);
var opJson = elasticsearchSerializer.SerializeToString(op, SerializationFormatting.None);
writer.WriteRaw($"{{\"{op.Operation}\":" + opJson + "}\n");
var body = op.GetBody();
if (body == null) continue;
var bodyJson = elasticsearchSerializer.SerializeToString(body, SerializationFormatting.None);
writer.WriteRaw(bodyJson + "\n");
}
}