From c8ec074efdeb4205fadf18b3eb7a1cdd818bd23d Mon Sep 17 00:00:00 2001 From: tanghai Date: Mon, 18 Sep 2017 09:43:12 +0800 Subject: [PATCH] =?UTF-8?q?mongo=20ios=E4=BF=AE=E6=94=B9=E7=94=A8aot?= =?UTF-8?q?=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Serialization/BsonMemberMap.cs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs b/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs index 133346a8..c9772aff 100644 --- a/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs +++ b/Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs @@ -16,7 +16,9 @@ using System; using System.Linq.Expressions; using System.Reflection; -//using System.Reflection.Emit; +#if !AOT +using System.Reflection.Emit; +#endif using MongoDB.Bson.Serialization.Serializers; namespace MongoDB.Bson.Serialization @@ -580,23 +582,25 @@ namespace MongoDB.Bson.Serialization throw new BsonSerializationException(message); } - // ios上不支持Emit - //var sourceType = fieldInfo.DeclaringType; - //var method = new DynamicMethod("Set" + fieldInfo.Name, null, new[] { typeof(object), typeof(object) }, true); - //var gen = method.GetILGenerator(); - // - //gen.Emit(OpCodes.Ldarg_0); - //gen.Emit(OpCodes.Castclass, sourceType); - //gen.Emit(OpCodes.Ldarg_1); - //gen.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType); - //gen.Emit(OpCodes.Stfld, fieldInfo); - //gen.Emit(OpCodes.Ret); - // - //return (Action)method.CreateDelegate(typeof(Action)); +#if AOT return (obj, value) => { fieldInfo.SetValue(obj, value); }; - } +#else + var sourceType = fieldInfo.DeclaringType; + var method = new DynamicMethod("Set" + fieldInfo.Name, null, new[] { typeof(object), typeof(object) }, true); + var gen = method.GetILGenerator(); + + gen.Emit(OpCodes.Ldarg_0); + gen.Emit(OpCodes.Castclass, sourceType); + gen.Emit(OpCodes.Ldarg_1); + gen.Emit(OpCodes.Unbox_Any, fieldInfo.FieldType); + gen.Emit(OpCodes.Stfld, fieldInfo); + gen.Emit(OpCodes.Ret); + + return (Action)method.CreateDelegate(typeof(Action)); +#endif + } - private Func GetGetter() + private Func GetGetter() { #if AOT PropertyInfo propertyInfo = _memberInfo as PropertyInfo; -- GitLab