AbpContractResolver.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Reflection;
  3. using Abp.Reflection;
  4. using Abp.Timing;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Serialization;
  7. namespace Abp.Json
  8. {
  9. public class AbpContractResolver : DefaultContractResolver
  10. {
  11. protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
  12. {
  13. JsonProperty property = base.CreateProperty(member, memberSerialization);
  14. ModifyProperty(member, property);
  15. return property;
  16. }
  17. protected virtual void ModifyProperty(MemberInfo member, JsonProperty property)
  18. {
  19. if (property.PropertyType != typeof(DateTime) && property.PropertyType != typeof(DateTime?))
  20. {
  21. return;
  22. }
  23. if (ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<DisableDateTimeNormalizationAttribute>(member) == null)
  24. {
  25. property.Converter = new AbpDateTimeConverter();
  26. }
  27. }
  28. }
  29. }