Support serialize dateTime format

This commit is contained in:
sunkaixuan
2019-04-13 20:06:19 +08:00
parent 4a32a80583
commit 1c5b396c70
4 changed files with 41 additions and 1 deletions

View File

@@ -134,6 +134,13 @@ namespace SqlSugar
get { return _NoSerialize; }
set { _NoSerialize = value; }
}
private string _SerializeDateTimeFormat;
public string SerializeDateTimeFormat
{
get { return _SerializeDateTimeFormat; }
set { _SerializeDateTimeFormat = value; }
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public partial class SugarDateTimeFormat
{
public const string Default = "yyyy-MM-dd HH:mm:ss";
public const string Date = "yyyy-MM-dd HH";
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
@@ -44,8 +45,26 @@ namespace SqlSugar
Writable = true,
ValueProvider = base.CreateMemberValueProvider(p)
}).ToList();
foreach (var item in list)
{
if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.DateType)
{
CreateDateProperty(type, item);
}
}
return list;
}
private static void CreateDateProperty(Type type, JsonProperty item)
{
var property = type.GetProperties().Where(it => it.Name == item.PropertyName).First();
var itemType = UtilMethods.GetUnderType(property);
if (property.GetCustomAttributes(true).Any(it => it is SugarColumn))
{
var sugarAttribute = (SugarColumn)property.GetCustomAttributes(true).First(it => it is SugarColumn);
item.Converter = new IsoDateTimeConverter() { DateTimeFormat = sugarAttribute.SerializeDateTimeFormat };
}
}
}
}

View File

@@ -87,6 +87,7 @@
<Compile Include="Entities\SugarDebugger.cs" />
<Compile Include="Enum\ConditionalType.cs" />
<Compile Include="Enum\DbType.cs" />
<Compile Include="Enum\SugarDateTimeFormat.cs" />
<Compile Include="Enum\WhereType.cs" />
<Compile Include="ExpressionsToSql\CaseWhen\CaseWhen.cs" />
<Compile Include="ExpressionsToSql\CaseWhen\CaseWhenResolve.cs" />