Support Json

This commit is contained in:
sunkaixuan 2019-05-16 19:38:56 +08:00
parent f1030ab8aa
commit 57d087f413
5 changed files with 31 additions and 9 deletions

View File

@ -8,7 +8,7 @@ namespace OrmTest
{
static void Main(string[] args)
{
//OldTestMain.Init();
OldTestMain.Init();
//Demo
Demo1_SqlSugarClient.Init();

View File

@ -113,7 +113,10 @@ namespace SqlSugar
{
if (columnInfo.PropertyInfo.PropertyType.IsClass() && columnInfo.PropertyInfo.PropertyType != UtilConstants.ByteArrayType && columnInfo.PropertyInfo.PropertyType != UtilConstants.ObjType)
{
BindClass(generator, result, columnInfo.PropertyInfo);
if (this.ReaderKeys.Any(it => it.Equals(fileName, StringComparison.CurrentCultureIgnoreCase)))
{
BindClass(generator, result, columnInfo,ReaderKeys.First(it => it.Equals(fileName, StringComparison.CurrentCultureIgnoreCase)));
}
}
else
{
@ -133,14 +136,24 @@ namespace SqlSugar
#endregion
#region Private methods
private bool IsIgnore(Type type, PropertyInfo propertyInfo)
private void BindClass(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
{
return Context.IgnoreColumns != null && Context.IgnoreColumns.Any(it => it.PropertyName.Equals(propertyInfo.Name, StringComparison.CurrentCultureIgnoreCase)
&& it.EntityName.Equals(type.Name, StringComparison.CurrentCultureIgnoreCase));
}
private void BindClass(ILGenerator generator, LocalBuilder result, PropertyInfo propertyInfo)
{
if (columnInfo.IsJson)
{
MethodInfo method = null;
int i = DataRecord.GetOrdinal(fieldName);
Label endIfLabel = generator.DefineLabel();
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldc_I4, i);
generator.Emit(OpCodes.Callvirt, isDBNullMethod);
generator.Emit(OpCodes.Brtrue, endIfLabel);
generator.Emit(OpCodes.Ldloc, result);
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldc_I4, i);
generator.Emit(OpCodes.Call, method);
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod());
generator.MarkLabel(endIfLabel);
}
}
private void BindField(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
{

View File

@ -169,6 +169,7 @@ namespace SqlSugar
column.IsEnableUpdateVersionValidation = sugarColumn.IsEnableUpdateVersionValidation;
column.IsTranscoding = sugarColumn.IsTranscoding;
column.SerializeDateTimeFormat = sugarColumn.SerializeDateTimeFormat;
column.IsJson = sugarColumn.IsJson;
}
else
{

View File

@ -29,5 +29,6 @@ namespace SqlSugar
public bool IsOnlyIgnoreInsert { get; set; }
public bool IsTranscoding { get; set; }
public string SerializeDateTimeFormat { get; set; }
public bool IsJson { get; set; }
}
}

View File

@ -141,6 +141,13 @@ namespace SqlSugar
get { return _SerializeDateTimeFormat; }
set { _SerializeDateTimeFormat = value; }
}
private bool _IsJson;
public bool IsJson
{
get { return _IsJson; }
set { _IsJson = value; }
}
}
}