网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using MongoDB.Bson;


namespace Dpz.Core.Infrastructure;


public class ObjectIdConverter:JsonConverter<ObjectId>
{
    public override ObjectId Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        if (ObjectId.TryParse(reader.GetString(),out var oid))
        {
            return oid;
        }
        throw new JsonException();
    }

    public override void Write(Utf8JsonWriter writer, ObjectId value, JsonSerializerOptions options)
    {
        writer.WriteStringValue(value.ToString());
    }
}
loading