Skip to content

Commit

Permalink
Comparer can be passed to DynamicTable to compare header values
Browse files Browse the repository at this point in the history
  • Loading branch information
Amberg committed Feb 5, 2024
1 parent c9fa65e commit 31d0fc9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions DocxTemplater/DynamicTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ namespace DocxTemplater
{
public class DynamicTable : IDynamicTable
{
private readonly IEqualityComparer<object> m_headerComparer;
private readonly List<Dictionary<object, object>> m_rows;
public IEnumerable<object> Headers => m_rows.SelectMany(x => x.Keys).Distinct().ToList();
public IEnumerable<object> Headers => m_rows.SelectMany(x => x.Keys).Distinct(m_headerComparer).ToList();

public IEnumerable<IEnumerable<object>> Rows => m_rows.Select(x => x.Values.ToList()).ToList();

public DynamicTable()
public DynamicTable(IEqualityComparer<object> headerComparer = null)
{
m_headerComparer = headerComparer ?? EqualityComparer<object>.Default;
m_rows = new List<Dictionary<object, object>>();
}

Expand Down

0 comments on commit 31d0fc9

Please sign in to comment.