MongoExtensions / src / BsonExtensions / Converters / BinaryDataBsonConverter.cs
Code · 15 lines · 502 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System.Text.Json.Serialization;
using System.Text.Json;

namespace BsonExtensions.Converters;

public class BinaryDataBsonConverter : JsonConverter<byte[]>
{
	public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		throw new NotImplementedException();
	}
	public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options) =>
		writer.WriteRawValue($"Binary(\"{Convert.ToBase64String(value)}\", 0)", true);
}