31 lines
893 B
C#
31 lines
893 B
C#
|
|
using System.Text.Encodings.Web;
|
|||
|
|
using System.Text.Json;
|
|||
|
|
using System.Text.Unicode;
|
|||
|
|
|
|||
|
|
namespace PARR.DAL.Extensions
|
|||
|
|
{
|
|||
|
|
public static class GeneralExtesions
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Преобразует объект в Json, с учетом Cyrillic
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="value"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string? ToJson(this object value)
|
|||
|
|
{
|
|||
|
|
if (value == null)
|
|||
|
|
return null;
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return JsonSerializer.Serialize(value, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All, UnicodeRanges.Cyrillic) }); ;
|
|||
|
|
}
|
|||
|
|
catch// (Exception ex)
|
|||
|
|
{
|
|||
|
|
// todo: писать лог??? или и так пойдет
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|