Skip to content

Commit

Permalink
Merge pull request #913 from mikependon/repodb-fixes
Browse files Browse the repository at this point in the history
Fix the issues when retrieving the PropertyValueAttribute from the Cl…
  • Loading branch information
mikependon authored Sep 17, 2021
2 parents ebd693b + 2c644fe commit 66e071e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NameAttribute>(declaringType, property)?.Name ??
property.Name;
}

Expand Down Expand Up @@ -182,14 +184,22 @@ public static IEnumerable<Field> AsFields(this PropertyInfo[] properties) =>
/// </summary>
/// <param name="propertyInfo">The target property.</param>
/// <returns>The list of mapped <see cref="PropertyHandlerAttribute"/> objects.</returns>
public static IEnumerable<PropertyValueAttribute> GetPropertyValueAttributes(this PropertyInfo propertyInfo) =>
propertyInfo?
public static IEnumerable<PropertyValueAttribute> 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;
}

/// <summary>
/// Returns the value of the data entity property. If the property handler is defined in the property, then the
Expand Down

0 comments on commit 66e071e

Please sign in to comment.