using AICore.Context.Entry; using System.Collections.Generic; using System.Linq; namespace AICore.Context.EntryMapper { internal abstract class BaseContextEntryMapper where TObject : class, new() where TContext : BaseContextEntry, new() { public virtual TContext MapToNewContext(TObject pObject) { var context = CreateNewContext(); MergeWithObject(pObject, context); return context; } public virtual TContext CreateNewContext() { return new TContext(); } public virtual IEnumerable MapToNewContexts(IEnumerable pObjects) { if (pObjects is null || !pObjects.Any()) return Enumerable.Empty(); return pObjects.Select(MapToNewContext); } public abstract void MergeWithObject(TObject pDataContract, TContext pContext); } }