Serialize converters were added

This commit is contained in:
Evgeny Redikultsev
2024-09-08 17:47:46 +05:00
parent 408e9f6999
commit 6e0b7b8070
60 changed files with 1713 additions and 443 deletions

View File

@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.JsonConverters
{
public class GetPropertyNameLogic : IGetPropertyNameLogic
{
public IShiftTraceLogger? TraceLogger { get; set; }
// Helper method to get the property name, considering [JsonProperty] and [JsonPropertyName] attributes
public string GetPropertyName(PropertyInfo prop)
{
// Check for [JsonProperty] attribute (for Newtonsoft.Json)
var jsonPropertyAttribute = prop.GetCustomAttribute<JsonPropertyAttribute>();
if (jsonPropertyAttribute != null)
{
return jsonPropertyAttribute.PropertyName;
}
// Check for [JsonPropertyName] attribute (for System.Text.Json compatibility)
var jsonPropertyNameAttribute = prop.GetCustomAttribute<System.Text.Json.Serialization.JsonPropertyNameAttribute>();
if (jsonPropertyNameAttribute != null)
{
return jsonPropertyNameAttribute.Name;
}
// Default to the property name if no attributes are found
return prop.Name;
}
}
}