Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion LINQtoCSV/CsvContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ namespace LINQtoCSV
/// </summary>
public class CsvContext
{
private class DefaultEntityFactory : IEntityFactory
{
public T AllocateObject<T>() where T : class, new()
{
return default(T);
}

public void ReleaseObject<T>(T entity) where T : class, new()
{
}
}

private readonly IEntityFactory _entityFactory;

/// ///////////////////////////////////////////////////////////////////////
/// Read
///
Expand Down Expand Up @@ -173,7 +187,7 @@ private IEnumerable<T> ReadData<T>(
}
else
{
T obj = default(T);
T obj = _entityFactory.AllocateObject<T>();
try
{
if (readingRawDataRows)
Expand Down Expand Up @@ -294,6 +308,12 @@ private void WriteData<T>(
/// </summary>
public CsvContext()
{
_entityFactory = new DefaultEntityFactory();
}

public CsvContext(IEntityFactory entityFactory)
{
_entityFactory = entityFactory;
}
}
}
8 changes: 8 additions & 0 deletions LINQtoCSV/IEntityFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace LINQtoCSV
{
public interface IEntityFactory
{
T AllocateObject<T>() where T : class, new();
void ReleaseObject<T>(T entity) where T : class, new();
}
}