23 lines
887 B
C#
23 lines
887 B
C#
using AyCode.Core.Interfaces;
|
|
using Newtonsoft.Json;
|
|
using TIAM.Core.Interfaces;
|
|
|
|
namespace TIAM.Core;
|
|
|
|
public static class SerializeObjectToJsonExtensions
|
|
{
|
|
private static string SerializeObjectToJson<T>(T source)
|
|
{
|
|
JsonSerializerSettings options = new()
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
};
|
|
|
|
return JsonConvert.SerializeObject(source, options);
|
|
}
|
|
|
|
public static string ToJson<T>(this T source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
public static string ToJson<T>(this IQueryable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
public static string ToJson<T>(this IEnumerable<T> source) where T : class, IAcSerializableToJson => SerializeObjectToJson(source);
|
|
} |