2023-09-22 15:30:57 +10:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Core.Common.Interfaces;
|
2023-09-22 15:30:57 +10:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
2026-04-14 16:27:27 +10:00
|
|
|
|
namespace PARR.Core.Common.Implementations
|
2023-09-22 15:30:57 +10:00
|
|
|
|
{
|
2023-11-17 16:03:36 +10:00
|
|
|
|
internal class TransformService: ITransformService
|
2023-09-22 15:30:57 +10:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<TransformService> logger;
|
|
|
|
|
|
|
|
|
|
|
|
public TransformService(ILogger<TransformService> logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T? GetModelFromJson<T>(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return JsonSerializer.Deserialize<T>(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError(ex, $"Ошибка при конвертации строки в модель. {str}");
|
|
|
|
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|