using AyCode.Utils.Extensions; using Mango.Nop.Core.Utils; using Nop.Core.Domain.Common; using System.Diagnostics.CodeAnalysis; namespace Mango.Nop.Core.Extensions; public static class GenericAttributeExtensions { public static TValue? GetValueOrNull(this IEnumerable src, string key) where TValue : struct { var ga = src.SingleOrDefault(x => x.Key == key); if (ga == null || ga.Value.IsNullOrWhiteSpace()) return null; return CommonHelper2.To(ga.Value); } public static TValue GetValueOrDefault(this IEnumerable src, string key, TValue defaultValue = default) where TValue : struct { var gaValue = GetValueOrNull(src, key); return gaValue == null ? defaultValue : CommonHelper2.To(gaValue); } public static bool TryGetValue(this IEnumerable src, string key, [NotNullWhen(true)] out TValue? value) where TValue : struct { value = null; var gaValue = GetValueOrNull(src, key); if (gaValue == null) return false; value = CommonHelper2.To(gaValue); return true; } }