mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 12:47:57 +08:00
Support Column No Serialize
This commit is contained in:
parent
2c7ff9d067
commit
4a32a80583
@ -128,6 +128,12 @@ namespace SqlSugar
|
|||||||
set { _IsTranscoding = value; }
|
set { _IsTranscoding = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _NoSerialize;
|
||||||
|
public bool NoSerialize
|
||||||
|
{
|
||||||
|
get { return _NoSerialize; }
|
||||||
|
set { _NoSerialize = value; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -6,17 +7,45 @@ using System.Text;
|
|||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
public class SerializeService:ISerializeService
|
public class SerializeService : ISerializeService
|
||||||
{
|
{
|
||||||
public string SerializeObject(object value)
|
public string SerializeObject(object value)
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(value);
|
return JsonConvert.SerializeObject(value, new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
ContractResolver = new MyContractResolver()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public T DeserializeObject<T>(string value)
|
public T DeserializeObject<T>(string value)
|
||||||
{
|
{
|
||||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new MyContractResolver() };
|
||||||
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class MyContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public MyContractResolver()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
var list = type.GetProperties()
|
||||||
|
.Where(x => !x.GetCustomAttributes(true).Any(a => (a is SugarColumn) && ((SugarColumn)a).NoSerialize == true))
|
||||||
|
.Select(p => new JsonProperty()
|
||||||
|
{
|
||||||
|
PropertyName = p.Name,
|
||||||
|
PropertyType = p.PropertyType,
|
||||||
|
Readable = true,
|
||||||
|
Writable = true,
|
||||||
|
ValueProvider = base.CreateMemberValueProvider(p)
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user