Эх сурвалжийг харах

Merge branch 'master' of https://github.com/egametang/ET

tanghai 7 жил өмнө
parent
commit
b8f6b57fe4

+ 16 - 0
Unity/Assets/Editor/Helper/MongoHelper.cs

@@ -4,6 +4,7 @@ using MongoDB.Bson;
 using MongoDB.Bson.IO;
 using MongoDB.Bson.Serialization;
 using MongoDB.Bson.Serialization.Serializers;
+using System.Collections.Generic;
 
 namespace ETModel
 {
@@ -69,5 +70,20 @@ namespace ETModel
 		{
 			return FromBson<T>(ToBson(t));
 		}
+
+
+        public static void AvoidAOT()
+        {
+            ArraySerializer<int> aint = new ArraySerializer<int>();
+            ArraySerializer<string> astring = new ArraySerializer<string>();
+            ArraySerializer<long> along = new ArraySerializer<long>();
+
+            EnumerableInterfaceImplementerSerializer<List<int>> e =
+                new EnumerableInterfaceImplementerSerializer<List<int>>();
+
+            EnumerableInterfaceImplementerSerializer<List<int>, int> elistint =
+                new EnumerableInterfaceImplementerSerializer<List<int>, int>();
+        }
+
 	}
 }

+ 21 - 5
Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs

@@ -19,6 +19,7 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq.Expressions;
 using System.Reflection;
+using System.Reflection.Emit;
 using System.Runtime.CompilerServices;
 #if NET45
 using System.Runtime.Serialization;
@@ -1277,10 +1278,25 @@ namespace MongoDB.Bson.Serialization
                 ConstructorInfo defaultConstructor = classTypeInfo.GetConstructors(bindingFlags)
                     .Where(c => c.GetParameters().Length == 0)
                     .SingleOrDefault();
-#if ENABLE_IL2CPP
-                _creator = () => defaultConstructor.Invoke(null);
-#else
-				if (defaultConstructor != null)
+                #if ENABLE_IL2CPP
+
+                if (defaultConstructor != null)
+                {
+                    _creator = () => defaultConstructor.Invoke(null);
+
+                }
+                else if(__getUninitializedObjectMethodInfo != null)
+                {
+
+                    _creator = () => __getUninitializedObjectMethodInfo.Invoke(null, new object[] { this._classType });
+                }
+                else
+                {
+                    var message = $"Type '{_classType.GetType().Name}' does not have a default constructor.";
+                    throw new BsonSerializationException(message);
+                }
+                #else
+                if (defaultConstructor != null)
                 {
                     // lambdaExpression = () => (object) new TClass()
                     body = Expression.New(defaultConstructor);
@@ -1298,7 +1314,7 @@ namespace MongoDB.Bson.Serialization
 
                 var lambdaExpression = Expression.Lambda<Func<object>>(body);
                 _creator = lambdaExpression.Compile();
-#endif
+                #endif
             }
             return _creator;
         }