using Mapster;
using Newtonsoft.Json;
using System.Linq;

namespace JiaZhiQuan.Common.Mapster
{
    public static class MapsterGlobalSettings
    {
        public static void DefaultMapsterGlobalSettings()
        {
            // 忽略大小写敏感
            TypeAdapterConfig.GlobalSettings
                             .Default
                             .NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
            // 如果配置了JsonPropertyAttribute，则使用JsonPropertyAttribute的PropertyName
            TypeAdapterConfig.GlobalSettings.Default
                             .GetMemberName(member => member.GetCustomAttributes(true)
                                                            .OfType<JsonPropertyAttribute>()
                                                            .FirstOrDefault()
                                                            ?.PropertyName);
        }
    }
}
