using System; using System.Collections.Generic; using System.Reflection; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Conventions; using TrueSync; using Unity.Mathematics; namespace ET { public static class MongoRegister { private static void RegisterStruct() where T : struct { BsonSerializer.RegisterSerializer(typeof (T), new StructBsonSerialize()); } public static void Init() { // 清理老的数据 MethodInfo createSerializerRegistry = typeof (BsonSerializer).GetMethod("CreateSerializerRegistry", BindingFlags.Static | BindingFlags.NonPublic); createSerializerRegistry.Invoke(null, Array.Empty()); MethodInfo registerIdGenerators = typeof (BsonSerializer).GetMethod("RegisterIdGenerators", BindingFlags.Static | BindingFlags.NonPublic); registerIdGenerators.Invoke(null, Array.Empty()); // 自动注册IgnoreExtraElements ConventionPack conventionPack = new() { new IgnoreExtraElementsConvention(true) }; ConventionRegistry.Register("IgnoreExtraElements", conventionPack, type => true); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); RegisterStruct(); Dictionary types = CodeTypes.Instance.GetTypes(); foreach (Type type in types.Values) { if (!type.IsSubclassOf(typeof (Object))) { continue; } if (type.IsGenericType) { continue; } BsonClassMap.LookupClassMap(type); } } } }