32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System.Reflection;
|
|
using Dapper;
|
|
using Galaeth.Core.Attributes.EntityAnnotation;
|
|
|
|
namespace Galaeth.DAL.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Entity attribute type mapper.
|
|
/// </summary>
|
|
public class EntityAttributeTypeMapper : FallbackTypeMapper
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="EntityAttributeTypeMapper"/> class.
|
|
/// </summary>
|
|
/// <param name="entityType">The entity type.</param>
|
|
public EntityAttributeTypeMapper(Type entityType)
|
|
: base([
|
|
new CustomPropertyTypeMap(
|
|
entityType,
|
|
(type, columnName) =>
|
|
type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
|
|
.FirstOrDefault(
|
|
prop =>
|
|
prop.GetCustomAttributes(false)
|
|
.OfType<ColumnMappingAttribute>()
|
|
.Any(attr => attr.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase)))),
|
|
new DefaultTypeMap(entityType)
|
|
])
|
|
{
|
|
}
|
|
}
|