提交 b8f6b57f 编写于 作者: T tanghai

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

......@@ -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>();
}
}
}
\ No newline at end of file
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册