You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
using Connected.Entities.Annotations;
|
|
using System.Reflection;
|
|
|
|
namespace Connected.Expressions.Mappings;
|
|
|
|
internal sealed class MemberMapping
|
|
{
|
|
public MemberMapping(PropertyInfo property)
|
|
{
|
|
Property = property;
|
|
|
|
Initialize();
|
|
}
|
|
|
|
private PropertyInfo Property { get; }
|
|
|
|
public MemberInfo MemberInfo => Property;
|
|
public bool IsValid { get; private set; }
|
|
public bool IsPrimaryKey { get; private set; }
|
|
public bool IsReadOnly { get; private set; }
|
|
public string Name { get; private set; }
|
|
|
|
public Type Type => Property.PropertyType;
|
|
private void Initialize()
|
|
{
|
|
var persistence = Property.GetCustomAttribute<PersistenceAttribute>();
|
|
|
|
if (persistence is null || persistence.Persistence.HasFlag(ColumnPersistence.Read))
|
|
IsValid = true;
|
|
|
|
IsReadOnly = persistence is not null && persistence.Persistence.HasFlag(ColumnPersistence.Read);
|
|
IsPrimaryKey = Property.GetCustomAttribute<PrimaryKeyAttribute>() is not null;
|
|
|
|
var memberAttribute = Property.GetCustomAttribute<MemberAttribute>();
|
|
|
|
if (memberAttribute is not null && !string.IsNullOrWhiteSpace(memberAttribute.Member))
|
|
Name = memberAttribute.Member;
|
|
else
|
|
Name = MemberInfo.Name.ToCamelCase();
|
|
}
|
|
}
|
|
|