using System; using Quadarax.Foundation.Core.Data.Interface.Entity; using Quadarax.Foundation.Core.Mapper; namespace Quadarax.Foundation.Core.Data.Mapper { public class Mapper : Loom where TMapper : class, new() { /// /// Singleton instance of this class. /// public static TMapper Instance => _instance.Value; private static readonly Lazy _instance = new Lazy(() => new TMapper()); #region ------ Constructors --------------------------------------------------------------- /// /// Initializes a new instance of this class. /// public Mapper() { } /// /// Defines mappings from a DAO to DTO and vice-versa. /// /// /// protected void DefineBiDirection() where TDao : class, IDao, new() where TDto : class, IDto, new() where TKey : IEquatable { Define() .PublicProperties() .Compile(); Define() .PublicProperties() .Compile(); } protected void Define(Action> customFromDao) where TDao : class, IDao, new() where TDto : class, IDto, new() { // from DAO to DTo var builder = Define(); builder.PublicProperties(); customFromDao?.Invoke(builder); builder.Compile(); } protected void DefineReverse(Action> customFromDao) where TDao : class, IDao, new() where TDto : class, IDto, new() { // from DTO to DAO var builder = Define(); builder.PublicProperties(); customFromDao?.Invoke(builder); builder.Compile(); } protected void DefineReverse() where TDao : class, IDao, new() where TDto : class, IDto, new() { // from DTO to DAO var builder = Define(); builder.PublicProperties(); builder.Compile(); } #endregion } }