mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Support serialize dateTime format
This commit is contained in:
@@ -134,6 +134,13 @@ namespace SqlSugar
|
||||
get { return _NoSerialize; }
|
||||
set { _NoSerialize = value; }
|
||||
}
|
||||
|
||||
private string _SerializeDateTimeFormat;
|
||||
public string SerializeDateTimeFormat
|
||||
{
|
||||
get { return _SerializeDateTimeFormat; }
|
||||
set { _SerializeDateTimeFormat = value; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
13
Src/Asp.Net/SqlSugar/Enum/SugarDateTimeFormat.cs
Normal file
13
Src/Asp.Net/SqlSugar/Enum/SugarDateTimeFormat.cs
Normal 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";
|
||||
}
|
||||
}
|
@@ -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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user