Files
BeWoPlaner/AICore/Context/EntryMapper/BaseContextEntryMapper.cs
2025-07-25 14:27:57 +02:00

35 lines
821 B
C#

using AICore.Context.Entry;
using System.Collections.Generic;
using System.Linq;
namespace AICore.Context.EntryMapper
{
public abstract class BaseContextEntryMapper<TObject, TContext>
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<TContext> MapToNewContexts(IEnumerable<TObject> pObjects)
{
if (pObjects is null || !pObjects.Any())
return Enumerable.Empty<TContext>();
return pObjects.Select(MapToNewContext);
}
public abstract void MergeWithObject(TObject pDataContract, TContext pContext);
}
}