本文整理汇总了C#中Newtonsoft.Json.JsonSerializer.GetConnectionSettings方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.GetConnectionSettings方法的具体用法?C# JsonSerializer.GetConnectionSettings怎么用?C# JsonSerializer.GetConnectionSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.GetConnectionSettings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var t = value as ITermsQuery;
if (t == null) return;
var settings = serializer.GetConnectionSettings();
var field = settings.Inferrer.Field(t.Field);
writer.WriteStartObject();
{
if (t.Terms.HasAny())
{
writer.WritePropertyName(field);
serializer.Serialize(writer, t.Terms);
}
else if (t.TermsLookup != null)
{
writer.WritePropertyName(field);
serializer.Serialize(writer, t.TermsLookup);
}
if (t.Boost.HasValue)
{
writer.WritePropertyName("boost");
writer.WriteValue(t.Boost.Value);
}
if (!t.Name.IsNullOrEmpty())
{
writer.WritePropertyName("_name");
writer.WriteValue(t.Name);
}
}
writer.WriteEndObject();
}
示例2: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var marker = value as Indices;
if (marker == null)
{
writer.WriteNull();
return;
}
marker.Match(
all =>
{
writer.WriteStartArray();
writer.WriteValue("_all");
writer.WriteEndArray();
},
many =>
{
var settings = serializer.GetConnectionSettings();
writer.WriteStartArray();
foreach (var m in many.Indices.Cast<IUrlParameter>())
writer.WriteValue(m.GetString(settings));
writer.WriteEndArray();
}
);
}
示例3: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var o = JObject.Load(reader);
var fields = o.Properties().ToDictionary(p => p.Name, p => p.Value.ToObject<object>());
var inferrer = serializer.GetConnectionSettings().Inferrer;
var fieldValues = new FieldValues(inferrer, fields);
return fieldValues;
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var property = value as PropertyName;
if (property == null)
{
writer.WriteNull();
return;
}
writer.WriteValue(new ElasticInferrer(serializer.GetConnectionSettings()).PropertyName(property));
}
示例5: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var field = value as Field;
if (field == null)
{
writer.WriteNull();
return;
}
var settings = serializer.GetConnectionSettings();
writer.WriteValue(settings.Inferrer.Field(field));
}
示例6: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var fields = value as Fields;
writer.WriteStartArray();
var infer = serializer.GetConnectionSettings().Inferrer;
foreach (var f in fields?.ListOfFields ?? Enumerable.Empty<Field>())
{
writer.WriteValue(infer.Field(f));
}
writer.WriteEndArray();
}
示例7: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var dictionary = value as IDictionary;
if (dictionary == null) return;
var settings = serializer.GetConnectionSettings();
var seenEntries = new Dictionary<string, object>();
foreach (DictionaryEntry entry in dictionary)
{
if (entry.Value == null && serializer.NullValueHandling == NullValueHandling.Ignore)
continue;
string key;
var fieldName = entry.Key as Field;
var propertyName = entry.Key as PropertyName;
var indexName = entry.Key as IndexName;
var typeName = entry.Key as TypeName;
if (settings == null)
key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
else if (fieldName != null)
key = settings.Inferrer.Field(fieldName);
else if (propertyName != null)
{
if (propertyName.Property != null)
{
IPropertyMapping mapping;
if (settings.PropertyMappings.TryGetValue(propertyName.Property, out mapping) && mapping.Ignore)
{
continue;
}
}
key = settings.Inferrer.PropertyName(propertyName);
}
else if (indexName != null)
key = settings.Inferrer.IndexName(indexName);
else if (typeName != null)
key = settings.Inferrer.TypeName(typeName);
else
key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
seenEntries[key] = entry.Value;
}
writer.WriteStartObject();
foreach(var entry in seenEntries)
{
writer.WritePropertyName(entry.Key);
serializer.Serialize(writer, entry.Value);
}
writer.WriteEndObject();
}
示例8: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var marker = value as Features;
if (marker == null)
{
writer.WriteNull();
return;
}
var settings = serializer.GetConnectionSettings();
var s = ((IUrlParameter)marker).GetString(settings);
writer.WriteValue(s);
}
示例9: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var marker = value as Indices;
if (marker == null)
{
writer.WriteNull();
return;
}
marker.Match(
all=> writer.WriteValue("_all"),
many => writer.WriteValue(((IUrlParameter)marker).GetString(serializer.GetConnectionSettings()))
);
}
示例10: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var marker = value as TypeName;
if (marker == null)
{
writer.WriteNull();
return;
}
var settings = serializer.GetConnectionSettings();
var typeName = settings.Inferrer.TypeName(marker);
writer.WriteValue(typeName);
}
示例11: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var id = value as Id;
if (id == null)
{
writer.WriteNull();
return;
}
if (id.Document != null)
{
var settings = serializer.GetConnectionSettings();
var indexName = settings.Inferrer.Id(id.Document.GetType(), id.Document);
writer.WriteValue(indexName);
}
else writer.WriteValue(id.Value);
}
示例12: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
return;
}
var id = (Id)value;
if (id.Document != null)
{
var settings = serializer.GetConnectionSettings();
var documentId = settings.Inferrer.Id(id.Document.GetType(), id.Document);
writer.WriteValue(documentId);
}
else writer.WriteValue(id.Value);
}
示例13: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var request = value as IMultiPercolateRequest;
if (request == null) return;
if (request.Percolations == null) return;
var settings = serializer.GetConnectionSettings();
var elasticsearchSerializer = settings.Serializer;
if (elasticsearchSerializer == null) return;
foreach (var percolation in request.Percolations)
{
var requestParameters = percolation.GetRequestParameters() ?? new PercolateRequestParameters();
var header = new PercolateHeader
{
percolate_index = requestParameters.GetQueryStringValue<string>("percolate_index"),
percolate_type = requestParameters.GetQueryStringValue<string>("percolate_type"),
routing = requestParameters.GetQueryStringValue<string[]>("routing"),
preference = requestParameters.GetQueryStringValue<string>("preference"),
percolate_routing = requestParameters.GetQueryStringValue<string>("percolate_routing"),
percolate_preference = requestParameters.GetQueryStringValue<string>("percolate_preference"),
version = requestParameters.GetQueryStringValue<long?>("version")
};
var routeValues = (percolation as IRequest)?.RouteValues;
if (routeValues != null)
{
header.id = routeValues.Get<Id>("id");
header.index = routeValues.Get<IndexName>("index");
header.type = routeValues.Get<TypeName>("type");
if (request.Index != null && request.Index.EqualsMarker(header.index)) header.index = null;
if (request.Type != null && request.Type.EqualsMarker(header.type)) header.type = null;
}
var headerBytes = elasticsearchSerializer.SerializeToBytes(header, SerializationFormatting.None);
writer.WriteRaw($"{{\"{percolation.MultiPercolateName}\":" + headerBytes.Utf8String() + "}\n");
if (percolation == null)
{
writer.WriteRaw("{}\n");
}
else
{
var bodyBytes = elasticsearchSerializer.SerializeToBytes(percolation, SerializationFormatting.None);
writer.WriteRaw(bodyBytes.Utf8String() + "\n");
}
}
}
示例14: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var dict = value as IDictionary<PropertyName, IProperty>;
if (dict == null) return;
var settings = serializer.GetConnectionSettings();
var props = new Properties();
foreach (var kv in dict)
{
var v = kv.Value as IPropertyWithClrOrigin;
if (v?.ClrOrigin == null)
{
props.Add(kv.Key, kv.Value);
continue;
}
//We do not have to take .Name into account from serializer PropertyName (kv.Key) already handles this
var serializerMapping = settings.Serializer?.CreatePropertyMapping(v.ClrOrigin);
if (serializerMapping == null || !serializerMapping.Ignore)
props.Add(kv.Key, kv.Value);
}
_dictionaryConverter.WriteJson(writer, props, serializer);
}
示例15: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var request = (IMultiSearchTemplateRequest)value;
if (request == null) return;
var settings = serializer.GetConnectionSettings();
var elasticsearchSerializer = settings.Serializer;
if (elasticsearchSerializer == null) return;
if (request.Operations == null) return;
foreach (var operation in request.Operations.Values)
{
IUrlParameter indices = request.Index == null || !request.Index.Equals(operation.Index)
? operation.Index
: null;
IUrlParameter types = request.Type == null || !request.Type.Equals(operation.Type)
? operation.Type
: null;
var searchType = operation.RequestParameters.GetQueryStringValue<SearchType>("search_type").GetStringValue();
if (searchType == "query_then_fetch")
searchType = null;
var header = new
{
index = indices?.GetString(settings),
type = types?.GetString(settings),
search_type = searchType,
preference = operation.Preference,
routing = operation.Routing,
ignore_unavailable = operation.IgnoreUnavalable
};
var headerString = elasticsearchSerializer.SerializeToString(header, SerializationFormatting.None);
writer.WriteRaw($"{headerString}\n");
var bodyString = elasticsearchSerializer.SerializeToString(operation, SerializationFormatting.None);
writer.WriteRaw($"{bodyString}\n");
};
}