修改导表 5
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-12-20 16:39:54 +08:00
parent e4b20908dc
commit 98ea3d1a92
2 changed files with 45 additions and 15 deletions
@@ -1,5 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace IRaCIS.Core.Infrastructure.Extention
{
@@ -38,7 +40,30 @@ namespace IRaCIS.Core.Infrastructure.Extention
public static string ToJsonNotIgnoreNull(this object obj)
{
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Include });
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Include });
}
}
public static Dictionary<string, object> ConvertToDictionary(this object obj)
{
if (obj == null)
{
throw new ArgumentNullException(nameof(obj));
}
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties();
Dictionary<string, object> dictionary = new Dictionary<string, object>();
foreach (PropertyInfo property in properties)
{
string propertyName = property.Name;
object propertyValue = property.GetValue(obj);
dictionary.Add(propertyName, propertyValue);
}
return dictionary;
}
}
}