Skip to content

Commit

Permalink
Merge pull request dotnetcore#244 from EternityTeam/master
Browse files Browse the repository at this point in the history
Json扩展支持JsonSerializerSettings
  • Loading branch information
2881099 authored Mar 21, 2020
2 parents 2f32e0e + 508743a commit 386354d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ public static class JsonMapCore
static object _isAopedLock = new object();
static ConcurrentDictionary<Type, bool> _dicTypes = new ConcurrentDictionary<Type, bool>();
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object) });
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object), typeof(JsonSerializerSettings) });

/// <summary>
/// 当实体类属性为【对象】时,并且标记特性 [JsonMap] 时,该属性将以JSON形式映射存储
/// </summary>
/// <returns></returns>
public static void UseJsonMap(this IFreeSql that)
{
UseJsonMap(that, null);
}

public static void UseJsonMap(this IFreeSql that, JsonSerializerSettings settings)
{
if (_isAoped == false)
lock(_isAopedLock)
lock (_isAopedLock)
if (_isAoped == false)
{
_isAoped = true;
Expand All @@ -46,13 +51,14 @@ public static void UseJsonMap(this IFreeSql that)
{
return Expression.IfThenElse(
Expression.TypeEqual(valueExp, e.Property.PropertyType),
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object))), typeof(object)),
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)),
elseExp);
});
}
}
});
}
}

}
}

0 comments on commit 386354d

Please sign in to comment.