Files

35 lines
823 B
C#
Raw Permalink Normal View History

2025-07-25 14:27:49 +02:00
using AICore.Context.Entry;
using System.Collections.Generic;
using System.Linq;
namespace AICore.Context.EntryMapper
{
2025-09-08 15:17:51 +02:00
internal abstract class BaseContextEntryMapper<TObject, TContext>
2025-07-25 14:27:49 +02:00
where TObject : class, new() where TContext : BaseContextEntry, new()
{
public virtual TContext MapToNewContext(TObject pObject)
{
2025-07-25 14:27:57 +02:00
var context = CreateNewContext();
MergeWithObject(pObject, context);
return context;
2025-07-25 14:27:49 +02:00
}
public virtual TContext CreateNewContext()
{
return new TContext();
}
public virtual IEnumerable<TContext> MapToNewContexts(IEnumerable<TObject> pObjects)
{
2025-07-25 14:27:57 +02:00
if (pObjects is null || !pObjects.Any())
2025-07-25 14:27:49 +02:00
return Enumerable.Empty<TContext>();
return pObjects.Select(MapToNewContext);
}
2025-07-25 14:27:57 +02:00
public abstract void MergeWithObject(TObject pDataContract, TContext pContext);
2025-07-25 14:27:49 +02:00
}
}