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(); if (persistence is null || persistence.Persistence.HasFlag(ColumnPersistence.Read)) IsValid = true; IsReadOnly = persistence is not null && persistence.Persistence.HasFlag(ColumnPersistence.Read); IsPrimaryKey = Property.GetCustomAttribute() is not null; var memberAttribute = Property.GetCustomAttribute(); if (memberAttribute is not null && !string.IsNullOrWhiteSpace(memberAttribute.Member)) Name = memberAttribute.Member; else Name = MemberInfo.Name.ToCamelCase(); } }