From 2c644fe888592594fd9fe1fa644456d85570c40b Mon Sep 17 00:00:00 2001 From: Michael Pendon Date: Sat, 18 Sep 2021 00:28:08 +0200 Subject: [PATCH] Fix the issues when retrieving the PropertyValueAttribute from the ClassProperty. --- .../RepoDb/Extensions/PropertyInfoExtension.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs b/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs index e862bb7d5..42ef0036b 100644 --- a/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs @@ -58,8 +58,10 @@ internal static string GetMappedName(this PropertyInfo property, var attributeName = ((MapAttribute)GetCustomAttribute(property, StaticType.MapAttribute))?.Name ?? ((ColumnAttribute)GetCustomAttribute(property, StaticType.ColumnAttribute))?.Name ?? ((NameAttribute)GetCustomAttribute(property, StaticType.NameAttribute))?.Name; + return attributeName ?? PropertyMapper.Get(declaringType, property) ?? + PropertyValueAttributeCache.GetAttribute(declaringType, property)?.Name ?? property.Name; } @@ -182,14 +184,22 @@ public static IEnumerable AsFields(this PropertyInfo[] properties) => /// /// The target property. /// The list of mapped objects. - public static IEnumerable GetPropertyValueAttributes(this PropertyInfo propertyInfo) => - propertyInfo? + public static IEnumerable GetPropertyValueAttributes(this PropertyInfo propertyInfo) + { + var attributes = propertyInfo? .GetCustomAttributes()? .Where(e => StaticType.PropertyValueAttribute.IsAssignableFrom(e.GetType())) .Select(e => - (PropertyValueAttribute)e) ?? - PropertyValueAttributeCache.Get(propertyInfo?.DeclaringType, propertyInfo); + (PropertyValueAttribute)e); + + attributes = attributes?.Any() == true ? attributes : + PropertyValueAttributeCache.Get(propertyInfo?.DeclaringType, propertyInfo); + + // TODO: Merge the 2 + + return attributes; + } /// /// Returns the value of the data entity property. If the property handler is defined in the property, then the