提交 88cf0b92 编写于 作者: T tanghai 提交者: GitHub

Merge pull request #9 from northroom/master

修复mongo.bson 在iOS下的AOT问题
......@@ -1274,9 +1274,12 @@ namespace MongoDB.Bson.Serialization
Expression body;
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var classTypeInfo = _classType.GetTypeInfo();
var defaultConstructor = classTypeInfo.GetConstructors(bindingFlags)
ConstructorInfo defaultConstructor = classTypeInfo.GetConstructors(bindingFlags)
.Where(c => c.GetParameters().Length == 0)
.SingleOrDefault();
#if AOT
_creator = () => defaultConstructor.Invoke(null);
#else
if (defaultConstructor != null)
{
// lambdaExpression = () => (object) new TClass()
......@@ -1295,6 +1298,7 @@ namespace MongoDB.Bson.Serialization
var lambdaExpression = Expression.Lambda<Func<object>>(body);
_creator = lambdaExpression.Compile();
#endif
}
return _creator;
}
......
......@@ -598,6 +598,24 @@ namespace MongoDB.Bson.Serialization
private Func<object, object> GetGetter()
{
#if AOT
PropertyInfo propertyInfo = _memberInfo as PropertyInfo;
if (propertyInfo != null)
{
MethodInfo getMethodInfo = propertyInfo.GetGetMethod();
if (getMethodInfo == null)
{
var message = string.Format(
"The property '{0} {1}' of class '{2}' has no 'get' accessor.",
propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName);
throw new BsonSerializationException(message);
}
return (obj) => { return getMethodInfo.Invoke(obj, null); };
}
FieldInfo fieldInfo = _memberInfo as FieldInfo;
return (obj) => { return fieldInfo.GetValue(obj); };
#else
var propertyInfo = _memberInfo as PropertyInfo;
if (propertyInfo != null)
{
......@@ -625,10 +643,17 @@ namespace MongoDB.Bson.Serialization
);
return lambdaExpression.Compile();
#endif
}
private Action<object, object> GetPropertySetter()
{
#if AOT
var propertyInfo = (PropertyInfo) _memberInfo;
return (obj, value) => { propertyInfo.SetValue(obj, value); };
#else
var propertyInfo = (PropertyInfo)_memberInfo;
var setMethodInfo = propertyInfo.SetMethod;
if (IsReadOnly)
......@@ -653,6 +678,7 @@ namespace MongoDB.Bson.Serialization
);
return lambdaExpression.Compile();
#endif
}
private void ThrowFrozenException()
......
......@@ -211,5 +211,13 @@ namespace Model
}
}
}
#if AOT
private void AvoidAot()
{
EnumSerializer<EntityType> e = new EnumSerializer<EntityType>();
}
#endif
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册