35 lines
945 B
C#
35 lines
945 B
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
|
|||
|
|
namespace Szmedi.Toolkit.Assists;
|
|||
|
|
|
|||
|
|
public abstract class BaseTypeConfiguration<T>
|
|||
|
|
{
|
|||
|
|
protected IList<PropertyConfiguration> Mappings { get; set; } = new List<PropertyConfiguration>();
|
|||
|
|
|
|||
|
|
public PropertyConfiguration Map<TProperty>(Expression<Func<T, TProperty>> expression)
|
|||
|
|
{
|
|||
|
|
var memberExpression = GetMemberExpression(expression);
|
|||
|
|
|
|||
|
|
var map = new PropertyConfiguration
|
|||
|
|
{
|
|||
|
|
Member = memberExpression.Member
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
Mappings.Add(map);
|
|||
|
|
|
|||
|
|
return map;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IList<PropertyConfiguration> GetMappings()
|
|||
|
|
{
|
|||
|
|
return Mappings;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected internal MemberExpression GetMemberExpression<TProperty>(Expression<Func<T, TProperty>> expression)
|
|||
|
|
{
|
|||
|
|
return expression.Body as MemberExpression ?? throw new ArgumentException("Expression Invalid.", nameof(expression));
|
|||
|
|
}
|
|||
|
|
}
|