/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); // TODO: does C# null need to round trip? } else { writer.WriteNull(); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { var fi = value as FieldInfo; var pi = value as PropertyInfo; var details = new { Name = fi != null ? fi.Name : pi != null ? pi.Name : null, MemberType = fi != null ? fi.FieldType : pi != null ? pi.PropertyType : null, }; if (details.Name != null) { serializer.Serialize(writer, details); } else { writer.WriteNull(); } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var binaryData = (BsonBinaryData)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteBinaryData(binaryData); } else { var jsonDotNetBsonWriter = writer as Newtonsoft.Json.Bson.BsonDataWriter; if (jsonDotNetBsonWriter != null && binaryData.SubType == BsonBinarySubType.Binary) { jsonDotNetBsonWriter.WriteValue(binaryData.Bytes); } else { WriteExtendedJson(writer, binaryData, serializer); } } } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonRegularExpression = (BsonRegularExpression)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteRegularExpression(bsonRegularExpression); } else { var jsonDotNetBsonWriter = writer as Newtonsoft.Json.Bson.BsonDataWriter; if (jsonDotNetBsonWriter != null) { jsonDotNetBsonWriter.WriteRegex(bsonRegularExpression.Pattern, bsonRegularExpression.Options); } else { WriteExtendedJson(writer, bsonRegularExpression); } } } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonDateTime = (BsonDateTime)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { var millisecondsSinceEpoch = bsonDateTime.MillisecondsSinceEpoch; adapter.WriteDateTime(millisecondsSinceEpoch); } else { if (bsonDateTime.IsValidDateTime) { writer.WriteValue(bsonDateTime.ToUniversalTime()); } else { WriteExtendedJson(writer, bsonDateTime); } } } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } writer.WriteValue(SchemaTest.HumanName((Type)value)); }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); // TODO: does C# null need to round trip? } else { var bsonType = ((BsonValue)value).BsonType; switch (bsonType) { case BsonType.Array: BsonArrayConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Binary: BsonBinaryDataConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Boolean: BsonBooleanConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.DateTime: BsonDateTimeConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Document: BsonDocumentConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Double: BsonDoubleConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Int32: BsonInt32Converter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Int64: BsonInt64Converter.Instance.WriteJson(writer, value, serializer); break; case BsonType.JavaScript: BsonJavaScriptConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.JavaScriptWithScope: BsonJavaScriptWithScopeConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.MaxKey: BsonMaxKeyConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.MinKey: BsonMinKeyConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Null: BsonNullConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.ObjectId: BsonObjectIdConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.RegularExpression: BsonRegularExpressionConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.String: BsonStringConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Symbol: BsonSymbolConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Timestamp: BsonTimestampConverter.Instance.WriteJson(writer, value, serializer); break; case BsonType.Undefined: BsonUndefinedConverter.Instance.WriteJson(writer, value, serializer); break; default: var message = string.Format("Unexpected BsonType: {0}.", bsonType); throw new Newtonsoft.Json.JsonSerializationException(message); } } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { WriteDocument(writer, (BsonDocument)value, serializer); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { writer.WriteValue(value.ToString()); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } string str = value.ToString().Substring(1, 2); writer.WriteValue(str); }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { writer.WriteUndefined(); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonObjectId = (BsonObjectId)value; serializer.Serialize(writer, bsonObjectId.Value); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonString = (BsonString)value; writer.WriteValue(bsonString.Value); } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } var enumerationType = value.GetType(); var factory = ValueFromEnumeration.GetOrAdd(enumerationType, (_) => MakeFuncValueDelegate(enumerationType)); writer.WriteValue(factory(value)); }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteMaxKey(); } else { WriteExtendedJson(writer); } } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var symbol = (BsonSymbol)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteSymbol(symbol.Name); } else { WriteExtendedJson(writer, symbol); } } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonInt32 = (BsonInt32)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteInt32(bsonInt32.Value); } else { writer.WriteValue((long)bsonInt32.Value); } } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonJavaScript = (BsonJavaScript)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteJavaScript(bsonJavaScript.Code); } else { WriteExtendedJson(writer, bsonJavaScript, serializer); } } }
public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var timestamp = (BsonTimestamp)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteTimestamp(timestamp.Value); } else { WriteExtendedJson(writer, timestamp); } } }
public static void WriteJson(this Newtonsoft.Json.JsonWriter writer, Neo.IO.Json.JObject json) { switch (json) { case null: writer.WriteNull(); break; case Neo.IO.Json.JBoolean boolean: writer.WriteValue(boolean.Value); break; case Neo.IO.Json.JNumber number: writer.WriteValue(number.Value); break; case Neo.IO.Json.JString @string: writer.WriteValue(@string.Value); break; case Neo.IO.Json.JArray @array: writer.WriteStartArray(); foreach (var value in @array) { WriteJson(writer, value); } writer.WriteEndArray(); break; case Neo.IO.Json.JObject @object: writer.WriteStartObject(); foreach (var(key, value) in @object.Properties) { writer.WritePropertyName(key); WriteJson(writer, value); } writer.WriteEndObject(); break; } }
/// <inheritdoc/> public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var bsonJavaScriptWithScope = (BsonJavaScriptWithScope)value; var adapter = writer as BsonWriterAdapter; if (adapter != null) { adapter.WriteJavaScriptWithScope(bsonJavaScriptWithScope.Code); var serializationContext = BsonSerializationContext.CreateRoot(adapter.WrappedWriter); BsonDocumentSerializer.Instance.Serialize(serializationContext, bsonJavaScriptWithScope.Scope); } else { WriteExtendedJson(writer, bsonJavaScriptWithScope, serializer); } } }
public void WriteNull() { _jsonWriter.WriteNull(); }